summaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/contexts/test_model.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/benchmark/contexts/test_model.py')
-rw-r--r--tests/unit/benchmark/contexts/test_model.py139
1 files changed, 136 insertions, 3 deletions
diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py
index 6ae4e6dac..3fb186b9b 100644
--- a/tests/unit/benchmark/contexts/test_model.py
+++ b/tests/unit/benchmark/contexts/test_model.py
@@ -170,6 +170,9 @@ class ServerTestCase(unittest.TestCase):
self.mock_context.keypair_name = 'some-keys'
self.mock_context.secgroup_name = 'some-secgroup'
self.mock_context.user = "some-user"
+ netattrs = {'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net'}
+ self.mock_context.networks = [model.Network("some-network", self.mock_context, netattrs)]
+
def test_construct_defaults(self):
@@ -208,13 +211,18 @@ class ServerTestCase(unittest.TestCase):
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test__add_instance(self, mock_template):
- attrs = {'image': 'some-image', 'flavor': 'some-flavor'}
+ attrs = {'image': 'some-image', 'flavor': 'some-flavor', 'floating_ip': '192.168.1.10', 'floating_ip_assoc': 'some-vm'}
test_server = model.Server('foo', self.mock_context, attrs)
+ self.mock_context.flavors = ['flavor1', 'flavor2', 'some-flavor']
+
mock_network = mock.Mock()
mock_network.name = 'some-network'
mock_network.stack_name = 'some-network-stack'
mock_network.subnet_stack_name = 'some-network-stack-subnet'
+ mock_network.provider = 'sriov'
+ mock_network.external_network = 'ext_net'
+ mock_network.router = model.Router('some-router', 'some-network', self.mock_context, 'ext_net')
test_server._add_instance(mock_template, 'some-server',
[mock_network], 'hints')
@@ -223,11 +231,136 @@ class ServerTestCase(unittest.TestCase):
'some-server-some-network-port',
mock_network.stack_name,
mock_network.subnet_stack_name,
- sec_group_id=self.mock_context.secgroup_name)
+ sec_group_id=self.mock_context.secgroup_name,
+ provider=mock_network.provider)
+
+ mock_template.add_floating_ip.assert_called_with(
+ 'some-server-fip',
+ mock_network.external_network,
+ 'some-server-some-network-port',
+ 'bar-some-network-some-router-if0',
+ 'some-secgroup'
+ )
+
+ mock_template.add_floating_ip_association.assert_called_with(
+ 'some-server-fip-assoc',
+ 'some-server-fip',
+ 'some-server-some-network-port'
+ )
mock_template.add_server.assert_called_with(
- 'some-server', 'some-image', 'some-flavor',
+ 'some-server', 'some-image',
+ flavor='some-flavor',
+ flavors=['flavor1', 'flavor2', 'some-flavor'],
ports=['some-server-some-network-port'],
user=self.mock_context.user,
key_name=self.mock_context.keypair_name,
+ user_data='',
+ scheduler_hints='hints')
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test__add_instance_with_user_data(self, mock_template):
+ user_data = "USER_DATA"
+ attrs = {
+ 'image': 'some-image', 'flavor': 'some-flavor',
+ 'user_data': user_data,
+ }
+ test_server = model.Server('foo', self.mock_context, attrs)
+
+ test_server._add_instance(mock_template, 'some-server',
+ [], 'hints')
+
+ mock_template.add_server.assert_called_with(
+ 'some-server', 'some-image',
+ flavor='some-flavor',
+ flavors=self.mock_context.flavors,
+ ports=[],
+ user=self.mock_context.user,
+ key_name=self.mock_context.keypair_name,
+ user_data=user_data,
+ scheduler_hints='hints')
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test__add_instance_plus_flavor(self, mock_template):
+
+ user_data = ''
+ attrs = {
+ 'image': 'some-image', 'flavor': 'flavor1',
+ 'flavors': ['flavor2'], 'user_data': user_data
+ }
+ test_server = model.Server('ServerFlavor-2', self.mock_context, attrs)
+
+ self.mock_context.flavors = ['flavor2']
+ mock_network = mock.Mock()
+ mock_network.configure_mock(name='some-network', stack_name= 'some-network-stack',
+ subnet_stack_name = 'some-network-stack-subnet',
+ provider = 'some-provider')
+
+ test_server._add_instance(mock_template, 'ServerFlavor-2',
+ [mock_network], 'hints')
+
+ mock_template.add_port.assert_called_with(
+ 'ServerFlavor-2-some-network-port',
+ mock_network.stack_name,
+ mock_network.subnet_stack_name,
+ provider=mock_network.provider,
+ sec_group_id=self.mock_context.secgroup_name)
+
+ mock_template.add_server.assert_called_with(
+ 'ServerFlavor-2', 'some-image',
+ flavor='flavor1',
+ flavors=['flavor2'],
+ ports=['ServerFlavor-2-some-network-port'],
+ user=self.mock_context.user,
+ key_name=self.mock_context.keypair_name,
+ user_data=user_data,
+ scheduler_hints='hints')
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test__add_instance_misc(self, mock_template):
+
+ user_data = ''
+ attrs = {
+ 'image': 'some-image', 'flavor': 'flavor1',
+ 'flavors': ['flavor2'], 'user_data': user_data
+ }
+ test_server = model.Server('ServerFlavor-3', self.mock_context, attrs)
+
+ self.mock_context.flavors = ['flavor2']
+ self.mock_context.flavor = {'vcpus': 4}
+ mock_network = mock.Mock()
+ mock_network.name = 'some-network'
+ mock_network.stack_name = 'some-network-stack'
+ mock_network.subnet_stack_name = 'some-network-stack-subnet'
+
+ test_server._add_instance(mock_template, 'ServerFlavor-3',
+ [mock_network], 'hints')
+
+
+ mock_template.add_port(
+ 'ServerFlavor-3-some-network-port',
+ mock_network.stack_name,
+ mock_network.subnet_stack_name,
+ sec_group_id=self.mock_context.secgroup_name)
+
+ mock_template.add_flavor(
+ vcpus=4,
+ ram=2048,
+ disk=1)
+
+ mock_template.add_flavor(
+ vcpus=4,
+ ram=2048,
+ disk=1,
+ extra_specs={'cat': 1, 'dog': 2, 'dragon': 1000})
+
+ mock_template.add_server.assert_called_with(
+ 'ServerFlavor-3', 'some-image',
+ flavor='flavor1',
+ flavors=['flavor2'],
+ ports=['ServerFlavor-3-some-network-port'],
+ user=self.mock_context.user,
+ key_name=self.mock_context.keypair_name,
+ user_data=user_data,
scheduler_hints='hints')
+