def mk_spec_and_host(spec_section, hosts, explicit_key, explicit, count):
if spec_section == 'hosts':
- mk_spec = lambda: ServiceSpec('mon', placement=PlacementSpec(
+ mk_spec = lambda: ServiceSpec('mgr', placement=PlacementSpec(
hosts=explicit,
count=count,
))
elif spec_section == 'label':
- mk_spec = lambda: ServiceSpec('mon', placement=PlacementSpec(
+ mk_spec = lambda: ServiceSpec('mgr', placement=PlacementSpec(
label='mylabel',
count=count,
))
'12': '[1-2]',
'123': '*',
}[explicit_key]
- mk_spec = lambda: ServiceSpec('mon', placement=PlacementSpec(
+ mk_spec = lambda: ServiceSpec('mgr', placement=PlacementSpec(
host_pattern=pattern,
count=count,
))
# | | | | |
test_explicit_scheduler_results = [
(k("* * 0 *"), error(ServiceSpecValidationError, 'num/count must be > 1')),
- (k("* e N l"), error(OrchestratorValidationError, 'Cannot place <ServiceSpec for service_name=mon>: No matching hosts for label mylabel')),
- (k("* e N p"), error(OrchestratorValidationError, 'Cannot place <ServiceSpec for service_name=mon>: No matching hosts')),
+ (k("* e N l"), error(OrchestratorValidationError, 'Cannot place <ServiceSpec for service_name=mgr>: No matching hosts for label mylabel')),
+ (k("* e N p"), error(OrchestratorValidationError, 'Cannot place <ServiceSpec for service_name=mgr>: No matching hosts')),
(k("* e N h"), error(OrchestratorValidationError, 'placement spec is empty: no hosts, no label, no pattern, no count')),
(k("* e * *"), none),
- (k("1 12 * h"), error(OrchestratorValidationError, "Cannot place <ServiceSpec for service_name=mon> on 2: Unknown hosts")),
- (k("1 123 * h"), error(OrchestratorValidationError, "Cannot place <ServiceSpec for service_name=mon> on 2, 3: Unknown hosts")),
+ (k("1 12 * h"), error(OrchestratorValidationError, "Cannot place <ServiceSpec for service_name=mgr> on 2: Unknown hosts")),
+ (k("1 123 * h"), error(OrchestratorValidationError, "Cannot place <ServiceSpec for service_name=mgr> on 2, 3: Unknown hosts")),
(k("1 * * *"), exactly('1')),
(k("12 1 * *"), exactly('1')),
(k("12 12 1 *"), one_of('1', '2')),
(k("12 12 * *"), exactly('1', '2')),
- (k("12 123 * h"), error(OrchestratorValidationError, "Cannot place <ServiceSpec for service_name=mon> on 3: Unknown hosts")),
+ (k("12 123 * h"), error(OrchestratorValidationError, "Cannot place <ServiceSpec for service_name=mgr> on 3: Unknown hosts")),
(k("12 123 1 *"), one_of('1', '2', '3')),
(k("12 123 * *"), two_of('1', '2', '3')),
(k("123 1 * *"), exactly('1')),
# | | | | | |
test_scheduler_daemons_results = [
(k("* 1 * * *"), exactly('1')),
- (k("1 123 * * h"), error(OrchestratorValidationError, 'Cannot place <ServiceSpec for service_name=mon> on 2, 3: Unknown hosts')),
+ (k("1 123 * * h"), error(OrchestratorValidationError, 'Cannot place <ServiceSpec for service_name=mgr> on 2, 3: Unknown hosts')),
(k("1 123 * * *"), exactly('1')),
- (k("12 123 * * h"), error(OrchestratorValidationError, 'Cannot place <ServiceSpec for service_name=mon> on 3: Unknown hosts')),
+ (k("12 123 * * h"), error(OrchestratorValidationError, 'Cannot place <ServiceSpec for service_name=mgr> on 3: Unknown hosts')),
(k("12 123 N * *"), exactly('1', '2')),
(k("12 123 1 * *"), one_of('1', '2')),
(k("12 123 2 * *"), exactly('1', '2')),
spec_section_key, spec_section):
mk_spec, hosts = mk_spec_and_host(spec_section, hosts, explicit_key, explicit, count)
dds = [
- DaemonDescription('mon', d, d)
+ DaemonDescription('mgr', d, d)
for d in daemons
]
run_scheduler_test(
[
# just hosts
NodeAssignmentTest(
- 'mon',
+ 'mgr',
PlacementSpec(hosts=['smithi060:[v2:172.21.15.60:3301,v1:172.21.15.60:6790]=c']),
['smithi060'],
[],
),
# all_hosts
NodeAssignmentTest(
- 'mon',
+ 'mgr',
PlacementSpec(host_pattern='*'),
'host1 host2 host3'.split(),
[
- DaemonDescription('mon', 'a', 'host1'),
- DaemonDescription('mon', 'b', 'host2'),
+ DaemonDescription('mgr', 'a', 'host1'),
+ DaemonDescription('mgr', 'b', 'host2'),
],
['host1', 'host2', 'host3']
),
),
# count + partial host list
NodeAssignmentTest(
- 'mon',
+ 'mgr',
PlacementSpec(count=3, hosts=['host3']),
'host1 host2 host3'.split(),
[
- DaemonDescription('mon', 'a', 'host1'),
- DaemonDescription('mon', 'b', 'host2'),
+ DaemonDescription('mgr', 'a', 'host1'),
+ DaemonDescription('mgr', 'b', 'host2'),
],
['host3']
),
# count 1 + partial host list
NodeAssignmentTest(
- 'mon',
+ 'mgr',
PlacementSpec(count=1, hosts=['host3']),
'host1 host2 host3'.split(),
[
- DaemonDescription('mon', 'a', 'host1'),
- DaemonDescription('mon', 'b', 'host2'),
+ DaemonDescription('mgr', 'a', 'host1'),
+ DaemonDescription('mgr', 'b', 'host2'),
],
['host3']
),
# count + partial host list + existing
NodeAssignmentTest(
- 'mon',
+ 'mgr',
PlacementSpec(count=2, hosts=['host3']),
'host1 host2 host3'.split(),
[
- DaemonDescription('mon', 'a', 'host1'),
+ DaemonDescription('mgr', 'a', 'host1'),
],
['host3']
),
# count + partial host list + existing (deterministic)
NodeAssignmentTest(
- 'mon',
+ 'mgr',
PlacementSpec(count=2, hosts=['host1']),
'host1 host2'.split(),
[
- DaemonDescription('mon', 'a', 'host1'),
+ DaemonDescription('mgr', 'a', 'host1'),
],
['host1']
),
# count + partial host list + existing (deterministic)
NodeAssignmentTest(
- 'mon',
+ 'mgr',
PlacementSpec(count=2, hosts=['host1']),
'host1 host2'.split(),
[
- DaemonDescription('mon', 'a', 'host2'),
+ DaemonDescription('mgr', 'a', 'host2'),
],
['host1']
),
# label only
NodeAssignmentTest(
- 'mon',
+ 'mgr',
PlacementSpec(label='foo'),
'host1 host2 host3'.split(),
[],
),
# host_pattern
NodeAssignmentTest(
- 'mon',
- PlacementSpec(host_pattern='mon*'),
- 'monhost1 monhost2 datahost'.split(),
+ 'mgr',
+ PlacementSpec(host_pattern='mgr*'),
+ 'mgrhost1 mgrhost2 datahost'.split(),
[],
- ['monhost1', 'monhost2']
+ ['mgrhost1', 'mgrhost2']
),
])
def test_node_assignment(service_type, placement, hosts, daemons, expected):
[
# just count
NodeAssignmentTest2(
- 'mon',
+ 'mgr',
PlacementSpec(count=1),
'host1 host2 host3'.split(),
[],
# hosts + (smaller) count
NodeAssignmentTest2(
- 'mon',
+ 'mgr',
PlacementSpec(count=1, hosts='host1 host2'.split()),
'host1 host2'.split(),
[],
),
# hosts + (smaller) count, existing
NodeAssignmentTest2(
- 'mon',
+ 'mgr',
PlacementSpec(count=1, hosts='host1 host2 host3'.split()),
'host1 host2 host3'.split(),
- [DaemonDescription('mon', 'mon.a', 'host1'),],
+ [DaemonDescription('mgr', 'mgr.a', 'host1'),],
1,
['host1', 'host2', 'host3'],
),
# hosts + (smaller) count, (more) existing
NodeAssignmentTest2(
- 'mon',
+ 'mgr',
PlacementSpec(count=1, hosts='host1 host2 host3'.split()),
'host1 host2 host3'.split(),
[
- DaemonDescription('mon', 'a', 'host1'),
- DaemonDescription('mon', 'b', 'host2'),
+ DaemonDescription('mgr', 'a', 'host1'),
+ DaemonDescription('mgr', 'b', 'host2'),
],
1,
['host1', 'host2']
),
# count + partial host list
NodeAssignmentTest2(
- 'mon',
+ 'mgr',
PlacementSpec(count=2, hosts=['host3']),
'host1 host2 host3'.split(),
[],
),
# label + count
NodeAssignmentTest2(
- 'mon',
+ 'mgr',
PlacementSpec(count=1, label='foo'),
'host1 host2 host3'.split(),
[],
[
# hosts + (smaller) count, (more) existing
NodeAssignmentTest2(
- 'mon',
+ 'mgr',
PlacementSpec(count=3, hosts='host3'.split()),
'host1 host2 host3'.split(),
[],
),
# count + partial host list
NodeAssignmentTest2(
- 'mon',
+ 'mgr',
PlacementSpec(count=2, hosts=['host3']),
'host1 host2 host3'.split(),
[],
[
# unknown host
NodeAssignmentTestBadSpec(
- 'mon',
+ 'mgr',
PlacementSpec(hosts=['unknownhost']),
['knownhost'],
[],
- "Cannot place <ServiceSpec for service_name=mon> on unknownhost: Unknown hosts"
+ "Cannot place <ServiceSpec for service_name=mgr> on unknownhost: Unknown hosts"
),
# unknown host pattern
NodeAssignmentTestBadSpec(
- 'mon',
+ 'mgr',
PlacementSpec(host_pattern='unknownhost'),
['knownhost'],
[],
- "Cannot place <ServiceSpec for service_name=mon>: No matching hosts"
+ "Cannot place <ServiceSpec for service_name=mgr>: No matching hosts"
),
# unknown label
NodeAssignmentTestBadSpec(
- 'mon',
+ 'mgr',
PlacementSpec(label='unknownlabel'),
[],
[],
- "Cannot place <ServiceSpec for service_name=mon>: No matching hosts for label unknownlabel"
+ "Cannot place <ServiceSpec for service_name=mgr>: No matching hosts for label unknownlabel"
),
])
def test_bad_specs(service_type, placement, hosts, daemons, expected):