From 37ac860fb8a7cf8dec83d117bc03c6fe906eafe1 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Fri, 24 Apr 2015 18:32:57 +0300 Subject: [PATCH] Terminate if accommodation is not satisfied Also rename parameter 'vm_accommodation' into 'accommodation'. Change-Id: I362213023f2fd7bdb7133044d67ffddd18571884 --- scenarios/misc/instance_metadata.yaml | 2 +- scenarios/networking/l2.yaml | 2 +- scenarios/networking/l2_dense.yaml | 2 +- scenarios/networking/l3_east_west.yaml | 2 +- scenarios/networking/l3_north_south.yaml | 2 +- scenarios/storage/dummy.yaml | 2 +- shaker/engine/deploy.py | 25 ++++++++++++------------ tests/test_deploy.py | 5 +++++ 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/scenarios/misc/instance_metadata.yaml b/scenarios/misc/instance_metadata.yaml index cc8ffcf..786d336 100644 --- a/scenarios/misc/instance_metadata.yaml +++ b/scenarios/misc/instance_metadata.yaml @@ -4,7 +4,7 @@ description: deployment: template: instance_metadata.hot - vm_accommodation: [single_room, density: 2, compute_nodes: 1] + accommodation: [single_room, density: 2, compute_nodes: 1] execution: tests: diff --git a/scenarios/networking/l2.yaml b/scenarios/networking/l2.yaml index d7dabda..a3b000d 100644 --- a/scenarios/networking/l2.yaml +++ b/scenarios/networking/l2.yaml @@ -6,7 +6,7 @@ description: deployment: template: l2.hot - vm_accommodation: [pair, single_room] + accommodation: [pair, single_room] execution: tests: diff --git a/scenarios/networking/l2_dense.yaml b/scenarios/networking/l2_dense.yaml index de9ae39..bcdc4c8 100644 --- a/scenarios/networking/l2_dense.yaml +++ b/scenarios/networking/l2_dense.yaml @@ -5,7 +5,7 @@ description: deployment: template: l2.hot - vm_accommodation: [pair, single_room, density: 4, compute_nodes: 2] + accommodation: [pair, single_room, density: 4, compute_nodes: 2] execution: size: 'quadratic_progression' diff --git a/scenarios/networking/l3_east_west.yaml b/scenarios/networking/l3_east_west.yaml index a6dec0d..b09e10f 100644 --- a/scenarios/networking/l3_east_west.yaml +++ b/scenarios/networking/l3_east_west.yaml @@ -4,7 +4,7 @@ description: deployment: template: l3_east_west.hot - vm_accommodation: [pair, single_room] + accommodation: [pair, single_room] execution: tests: diff --git a/scenarios/networking/l3_north_south.yaml b/scenarios/networking/l3_north_south.yaml index 4d1a182..e49653d 100644 --- a/scenarios/networking/l3_north_south.yaml +++ b/scenarios/networking/l3_north_south.yaml @@ -5,7 +5,7 @@ description: deployment: template: l3_north_south.hot - vm_accommodation: [pair, double_room] + accommodation: [pair, double_room] execution: size: 'quadratic_progression' diff --git a/scenarios/storage/dummy.yaml b/scenarios/storage/dummy.yaml index 70e35c6..4b55815 100644 --- a/scenarios/storage/dummy.yaml +++ b/scenarios/storage/dummy.yaml @@ -3,7 +3,7 @@ description: deployment: template: dummy.hot - vm_accommodation: [single_room] + accommodation: [single_room] execution: tests: diff --git a/shaker/engine/deploy.py b/shaker/engine/deploy.py index d18a813..5d2c489 100644 --- a/shaker/engine/deploy.py +++ b/shaker/engine/deploy.py @@ -26,9 +26,9 @@ from shaker.openstack.clients import openstack LOG = logging.getLogger(__name__) -def generate_agents(compute_nodes, vm_accommodation, unique): +def generate_agents(compute_nodes, accommodation, unique): density = 1 - for s in vm_accommodation: + for s in accommodation: if isinstance(s, dict): if s.get('density'): density = s.get('density') @@ -38,41 +38,41 @@ def generate_agents(compute_nodes, vm_accommodation, unique): cn_count = len(compute_nodes) iterations = cn_count * density - if 'single_room' in vm_accommodation and 'pair' in vm_accommodation: + if 'single_room' in accommodation and 'pair' in accommodation: iterations //= 2 node_formula = lambda x: compute_nodes[x % cn_count] agents = {} for i in range(iterations): - if 'pair' in vm_accommodation: + if 'pair' in accommodation: master_id = '%s_master_%s' % (unique, i) slave_id = '%s_slave_%s' % (unique, i) master = dict(id=master_id, mode='master', slave_id=slave_id) slave = dict(id=slave_id, mode='slave', master_id=master_id) - if 'single_room' in vm_accommodation: + if 'single_room' in accommodation: master['node'] = node_formula(i * 2) slave['node'] = node_formula(i * 2 + 1) - elif 'double_room' in vm_accommodation: + elif 'double_room' in accommodation: master['node'] = node_formula(i) slave['node'] = node_formula(i) - elif 'mixed_room' in vm_accommodation: + elif 'mixed_room' in accommodation: master['node'] = node_formula(i) slave['node'] = node_formula(i + 1) agents[master['id']] = master agents[slave['id']] = slave else: - if 'single_room' in vm_accommodation: + if 'single_room' in accommodation: agent_id = '%s_agent_%s' % (unique, i) agents[agent_id] = dict(id=agent_id, node=node_formula(i), mode='alone') if not agents: - LOG.warning('Not enough compute nodes %(cn)s for requested ' - 'instance accommodation %(acc)s', - dict(cn=compute_nodes, acc=vm_accommodation)) + raise Exception('Not enough compute nodes %(cn)s for requested ' + 'instance accommodation %(acc)s' % + dict(cn=compute_nodes, acc=accommodation)) return agents @@ -145,7 +145,8 @@ class Deployment(object): def _deploy_from_hot(self, specification, base_dir=None): agents = generate_agents( nova.get_available_compute_nodes(self.openstack_client.nova), - specification['vm_accommodation'], + specification.get('accommodation') or + specification.get('vm_accommodation'), self.stack_name) # render template by jinja diff --git a/tests/test_deploy.py b/tests/test_deploy.py index 68af1ff..d05474a 100644 --- a/tests/test_deploy.py +++ b/tests/test_deploy.py @@ -56,6 +56,11 @@ class TestDeploy(testtools.TestCase): unique) self.assertEqual(expected, actual) + def test_generate_agents_pair_single_room_not_enough(self): + unique = 'UU1D' + self.assertRaises(Exception, deploy.generate_agents, ['uno'], + ['pair', 'single_room'], unique) # NOQA + def test_generate_agents_pair_double_room(self): unique = 'UU1D' expected = {