Skip to content

Commit efed173

Browse files
patapenka-alexeyoleg-jukovec
authored andcommitted
pack: skip unavailable configs from etcd and tcs
@TarantoolBot document Title: pack: skip configs from etcd and tcs This patch fixes the `tt pack` error if `etcd` or `tcs` are unavailable during package creation. Part of #1038
1 parent 5105bea commit efed173

File tree

11 files changed

+258
-11
lines changed

11 files changed

+258
-11
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4242

4343
- `tt coredump inspect`: fails for tarantool-ee coredump archive if the source
4444
directory is missing.
45+
- `tt pack`: fails if `etcd` or `tcs` are present in the configuration
46+
and not available.
4547

4648
## [2.6.0] - 2024-11-29
4749

cli/pack/opts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func initAppsInfo(cliOpts *config.CliOpts, cmdCtx *cmdcontext.CmdCtx, packCtx *P
4949
}
5050
packCtx.AppList = appList
5151
packCtx.AppsInfo, err = running.CollectInstancesForApps(packCtx.AppList, cliOpts,
52-
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, true)
52+
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, false)
5353
if err != nil {
5454
return fmt.Errorf("failed to collect applications info: %s", err)
5555
}

cli/running/running.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func loadInstanceConfig(configPath, instName string,
348348

349349
// collectInstancesFromAppDir collects instances information from application directory.
350350
func collectInstancesFromAppDir(appDir string, selectedInstName string,
351-
integrityCtx integrity.IntegrityCtx, instancesScriptsRequired bool) (
351+
integrityCtx integrity.IntegrityCtx, configRequired bool) (
352352
[]InstanceCtx,
353353
error,
354354
) {
@@ -376,7 +376,7 @@ func collectInstancesFromAppDir(appDir string, selectedInstName string,
376376
InstName: filepath.Base(appDir),
377377
AppDir: appDir,
378378
SingleApp: true}}, nil
379-
} else if instancesScriptsRequired {
379+
} else if configRequired {
380380
return nil, fmt.Errorf("require files are missing in application directory %q: "+
381381
"there must be instances config or the default instance script (%q)",
382382
appDir, "init.lua")
@@ -410,15 +410,15 @@ func collectInstancesFromAppDir(appDir string, selectedInstName string,
410410
log.Debugf("Instance %q", instance.InstName)
411411

412412
if instance.Configuration, err = loadInstanceConfig(instance.ClusterConfigPath,
413-
instance.InstName, integrityCtx); err != nil {
413+
instance.InstName, integrityCtx); err != nil && configRequired {
414414
return instances, fmt.Errorf("error loading instance %q configuration from "+
415415
"config %q: %w", instance.InstName, instance.ClusterConfigPath, err)
416416
}
417417

418418
instance.SingleApp = false
419419
if instance.InstanceScript, err = findInstanceScriptInAppDir(appDir, instance.InstName,
420420
appDirFiles.clusterCfgPath, appDirFiles.defaultLuaPath); err != nil &&
421-
instancesScriptsRequired {
421+
configRequired {
422422
return instances, fmt.Errorf("cannot find instance script for %q in config %q: %w ",
423423
instance.InstName, appDirFiles.clusterCfgPath, err)
424424
}
@@ -434,7 +434,7 @@ func collectInstancesFromAppDir(appDir string, selectedInstName string,
434434

435435
// CollectInstances searches all instances available in application.
436436
func CollectInstances(appName string, applicationsDir string,
437-
integrityCtx integrity.IntegrityCtx, instancesScriptsRequired bool) ([]InstanceCtx, error) {
437+
integrityCtx integrity.IntegrityCtx, configRequired bool) ([]InstanceCtx, error) {
438438
// The user can select a specific instance from the application.
439439
// Example: `tt status application:server`.
440440
selectedInstName := ""
@@ -463,7 +463,7 @@ func CollectInstances(appName string, applicationsDir string,
463463
}
464464

465465
return collectInstancesFromAppDir(appDir, selectedInstName, integrityCtx,
466-
instancesScriptsRequired)
466+
configRequired)
467467
}
468468

469469
// cleanup removes runtime artifacts.
@@ -625,7 +625,7 @@ func GetClusterConfigPath(cliOpts *config.CliOpts,
625625

626626
// CollectInstancesForApps collects instances information per application.
627627
func CollectInstancesForApps(appList []string, cliOpts *config.CliOpts,
628-
ttConfigDir string, integrityCtx integrity.IntegrityCtx, instancesScriptsRequired bool) (
628+
ttConfigDir string, integrityCtx integrity.IntegrityCtx, configRequired bool) (
629629
map[string][]InstanceCtx, error) {
630630
instEnabledPath := cliOpts.Env.InstancesEnabled
631631
if cliOpts.Env.InstancesEnabled == "." {
@@ -635,7 +635,7 @@ func CollectInstancesForApps(appList []string, cliOpts *config.CliOpts,
635635
for _, appName := range appList {
636636
appName = strings.TrimSuffix(appName, ".lua")
637637
collectedInstances, err := CollectInstances(appName, instEnabledPath, integrityCtx,
638-
instancesScriptsRequired)
638+
configRequired)
639639
if err != nil {
640640
return apps, fmt.Errorf("can't collect instance information for %s: %w",
641641
appName, err)
@@ -676,7 +676,7 @@ func createInstanceDataDirectories(instance InstanceCtx) error {
676676

677677
// FillCtx fills the RunningCtx context.
678678
func FillCtx(cliOpts *config.CliOpts, cmdCtx *cmdcontext.CmdCtx,
679-
runningCtx *RunningCtx, args []string, instancesScriptsRequired bool) error {
679+
runningCtx *RunningCtx, args []string, configRequired bool) error {
680680
var err error
681681

682682
if len(args) > 1 && cmdCtx.CommandName != "run" && cmdCtx.CommandName != "connect" &&
@@ -703,7 +703,7 @@ func FillCtx(cliOpts *config.CliOpts, cmdCtx *cmdcontext.CmdCtx,
703703
}
704704

705705
instances, err := CollectInstancesForApps(appList, cliOpts,
706-
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, instancesScriptsRequired)
706+
cmdCtx.Cli.ConfigDir, cmdCtx.Integrity, configRequired)
707707
if err != nil {
708708
return err
709709
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test_app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
credentials:
2+
users:
3+
client:
4+
password: 'secret'
5+
roles: [super]
6+
replicator:
7+
password: 'secret'
8+
roles: [replication]
9+
storage:
10+
password: 'secret'
11+
roles: [sharding]
12+
13+
iproto:
14+
advertise:
15+
peer:
16+
login: replicator
17+
sharding:
18+
login: storage
19+
20+
sharding:
21+
bucket_count: 3000
22+
23+
groups:
24+
storages:
25+
app:
26+
module: storage
27+
sharding:
28+
roles: [storage]
29+
replication:
30+
failover: manual
31+
replicasets:
32+
storage-001:
33+
leader: storage-001-a
34+
instances:
35+
storage-001-a:
36+
iproto:
37+
listen:
38+
- uri: localhost:3301
39+
storage-001-b:
40+
iproto:
41+
listen:
42+
- uri: localhost:3302
43+
storage-002:
44+
leader: storage-002-a
45+
instances:
46+
storage-002-a:
47+
iproto:
48+
listen:
49+
- uri: localhost:3303
50+
storage-002-b:
51+
iproto:
52+
listen:
53+
- uri: localhost:3304
54+
routers:
55+
app:
56+
module: router
57+
sharding:
58+
roles: [router]
59+
replicasets:
60+
router-001:
61+
instances:
62+
router-001-a:
63+
iproto:
64+
listen:
65+
- uri: localhost:3305
66+
config:
67+
etcd:
68+
endpoints:
69+
- http://localhost:2379
70+
prefix: /test_app
71+
username: client
72+
password: secret
73+
http:
74+
request:
75+
timeout: 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
storage-001-a:
3+
4+
storage-001-b:
5+
6+
storage-002-a:
7+
8+
storage-002-b:
9+
10+
router-001-a:
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
local vshard = require('vshard')
2+
local log = require('log')
3+
4+
-- Bootstrap the vshard router.
5+
while true do
6+
local ok, err = vshard.router.bootstrap({
7+
if_not_bootstrapped = true,
8+
})
9+
if ok then
10+
break
11+
end
12+
log.info(('Router bootstrap error: %s'):format(err))
13+
end
14+
15+
-- Put data into the cluster.
16+
function put(id, name, age)
17+
local bucket_id = vshard.router.bucket_id_mpcrc32({id})
18+
vshard.router.callrw(bucket_id, 'put', {id, bucket_id, name, age})
19+
end
20+
21+
-- Get data from the cluster.
22+
function get(id)
23+
local bucket_id = vshard.router.bucket_id_mpcrc32({id})
24+
return vshard.router.callro(bucket_id, 'get', {id})
25+
end
26+
27+
-- Put sample data.
28+
function put_sample_data()
29+
put(1, 'Elizabeth', 12)
30+
put(2, 'Mary', 46)
31+
put(3, 'David', 33)
32+
put(4, 'William', 81)
33+
put(5, 'Jack', 35)
34+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
local vshard = require('vshard')
2+
3+
-- Create 'customers' space.
4+
box.once('customers', function()
5+
box.schema.create_space('customers', {
6+
format = {{
7+
name = 'id',
8+
type = 'unsigned'
9+
}, {
10+
name = 'bucket_id',
11+
type = 'unsigned'
12+
}, {
13+
name = 'name',
14+
type = 'string'
15+
}, {
16+
name = 'age',
17+
type = 'number'
18+
}}
19+
})
20+
box.space.customers:create_index('primary_index', {
21+
parts = {{
22+
field = 1,
23+
type = 'unsigned'
24+
}}
25+
})
26+
box.space.customers:create_index('bucket_id', {
27+
parts = {{
28+
field = 2,
29+
type = 'unsigned'
30+
}},
31+
unique = false
32+
})
33+
box.space.customers:create_index('age', {
34+
parts = {{
35+
field = 4,
36+
type = 'number'
37+
}},
38+
unique = false
39+
})
40+
end)
41+
42+
-- Put data to the 'customers' space.
43+
-- Function should be called by the router.
44+
function put(id, bucket_id, name, age)
45+
box.space.customers:insert({id, bucket_id, name, age})
46+
end
47+
48+
-- Get data from the 'customers' space.
49+
-- Function should be called by the router.
50+
function get(id)
51+
local tuple = box.space.customers:get(id)
52+
if tuple == nil then
53+
return nil
54+
end
55+
return {tuple.id, tuple.name, tuple.age}
56+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package = 'test_app'
2+
version = 'scm-1'
3+
source = {
4+
url = '/dev/null',
5+
}
6+
dependencies = {
7+
'vshard == 0.1.25'
8+
}
9+
build = {
10+
type = 'none';
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
env:
2+
bin_dir: bin
3+
inc_dir: include
4+
instances_enabled: instances.enabled
5+
restart_on_failure: false
6+
tarantoolctl_layout: false
7+
modules:
8+
directory: modules
9+
app:
10+
run_dir: var/run
11+
log_dir: var/log
12+
wal_dir: var/lib
13+
memtx_dir: var/lib
14+
vinyl_dir: var/lib
15+
ee:
16+
credential_path: ""
17+
templates:
18+
- path: templates
19+
repo:
20+
rocks: ""
21+
distfiles: distfiles

test/integration/pack/test_pack.py

+36
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def assert_single_app_env(config):
5555
assert config["env"]["bin_dir"] == "bin"
5656

5757

58+
def assert_vshard_app_env(config):
59+
assert config["env"]["instances_enabled"] == "instances.enabled"
60+
assert config["env"]["bin_dir"] == "bin"
61+
assert config["env"]["inc_dir"] == "include"
62+
63+
5864
def assert_artifacts_env(config):
5965
assert config["app"]["wal_dir"] == "var/lib"
6066
assert config["app"]["vinyl_dir"] == "var/lib"
@@ -520,6 +526,36 @@ def prepare_tgz_test_cases(tt_cmd) -> list:
520526
],
521527
"check_env": ["myapp", assert_single_app_env, assert_artifacts_env]
522528
},
529+
{
530+
"name": "Vshard app packing",
531+
"bundle_src": "vshard_app",
532+
"cmd": tt_cmd,
533+
"pack_type": "tgz",
534+
"args": ["--name", "test_app"],
535+
"res_file": "test_app-0.1.0.0." + get_arch() + ".tar.gz",
536+
"check_exist": [
537+
os.path.join("bin", "tarantool"),
538+
os.path.join("bin", "tt"),
539+
os.path.join("instances.enabled", "test_app"),
540+
"tt.yaml",
541+
"test_app/config.yaml",
542+
"test_app/instances.yaml",
543+
"test_app/router.lua",
544+
"test_app/storage.lua",
545+
],
546+
"check_not_exist": [
547+
"test_app/test_app-scm-1.rockspec",
548+
"test_app/tt.yaml",
549+
"include",
550+
"modules",
551+
"templates",
552+
os.path.join("test_app", "include"),
553+
os.path.join("test_app", "modules"),
554+
os.path.join("test_app", "templates"),
555+
os.path.join("test_app", "distfiles"),
556+
],
557+
"check_env": [".", assert_vshard_app_env, assert_artifacts_env]
558+
},
523559
]
524560

525561

0 commit comments

Comments
 (0)