diff options
author | Stepan Andrushko <stepanx.andrushko@intel.com> | 2018-08-28 13:30:19 +0300 |
---|---|---|
committer | Stepan Andrushko <stepanx.andrushko@intel.com> | 2018-08-29 20:27:00 +0300 |
commit | c3a9c990edce2d393ae65b8090aae64a729b59d9 (patch) | |
tree | 0a45370436c04dc92bdd84199c3465a7314a555d /yardstick/tests | |
parent | 749a77816a4ecd1adee41f896c6e6fc779127046 (diff) |
Assign static IP to VM for standalone context
During VM spawning IP address should be assigned by DHCP server in
the local network. Sometimes DHCP server is not capable to assign IP
address. So, need to add static IP address.
JIRA: YARDSTICK-1402
Change-Id: Ie59c340eb88eddcaff043496fc20aa48b49205ec
Signed-off-by: Stepan Andrushko <stepanx.andrushko@intel.com>
Diffstat (limited to 'yardstick/tests')
3 files changed, 27 insertions, 10 deletions
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py index 371e4ef36..98d2b1836 100644 --- a/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py +++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py @@ -205,10 +205,13 @@ class ModelLibvirtTestCase(unittest.TestCase): hostname = root.find('name').text meta_data = "/tmp/meta-data" user_data = "/tmp/user-data" + network_data = "/tmp/network-config" file_path = "/tmp/cdrom-0.img" key_filename = "id_rsa" pub_key_str = "KEY" user = 'root' + mac = "00:11:22:33:44:55" + ip = "1.1.1.7/24" user_config = [" - name: {user_name}", " ssh_authorized_keys:", " - {pub_key_str}"] @@ -218,7 +221,8 @@ class ModelLibvirtTestCase(unittest.TestCase): create=True) as mock_file: with open(key_filename, "r") as h: result = h.read() - model.Libvirt.gen_cdrom_image(self.mock_ssh, file_path, hostname, user, key_filename) + model.Libvirt.gen_cdrom_image(self.mock_ssh, file_path, hostname, user, key_filename, + mac, ip) mock_file.assert_called_with(".".join([key_filename, "pub"]), "r") self.assertEqual(result, pub_key_str) @@ -226,9 +230,12 @@ class ModelLibvirtTestCase(unittest.TestCase): mock.call("touch %s" % meta_data), mock.call(model.USER_DATA_TEMPLATE.format(user_file=user_data, host=hostname, user_config=user_conf)), + mock.call(model.NETWORK_DATA_TEMPLATE.format(network_file=network_data, + mac_address=mac, ip_address=ip)), mock.call("genisoimage -output {0} -volid cidata" - " -joliet -r {1} {2}".format(file_path, meta_data, user_data)), - mock.call("rm {0} {1}".format(meta_data, user_data)) + " -joliet -r {1} {2} {3}".format(file_path, meta_data, user_data, + network_data)), + mock.call("rm {0} {1} {2}".format(meta_data, user_data, network_data)) ]) def test_create_snapshot_qemu(self): @@ -273,16 +280,22 @@ class ModelLibvirtTestCase(unittest.TestCase): @mock.patch.object(model.Libvirt, 'gen_cdrom_image') def test_check_update_key(self, mock_gen_cdrom_image): - node = {'user': 'defuser', 'key_filename': '/home/ubuntu/id_rsa'} + node = { + 'user': 'defuser', + 'key_filename': '/home/ubuntu/id_rsa', + 'ip': '1.1.1.7', + 'netmask': '255.255.255.0'} cdrom_img = "/var/lib/libvirt/images/data.img" id_name = 'fake_name' key_filename = node.get('key_filename') root = ElementTree.fromstring(self.XML_STR) hostname = root.find('name').text + mac = "00:11:22:33:44:55" + ip = "{0}/{1}".format(node.get('ip'), node.get('netmask')) model.StandaloneContextHelper.check_update_key(self.mock_ssh, node, hostname, id_name, - cdrom_img) + cdrom_img, mac) mock_gen_cdrom_image.assert_called_once_with(self.mock_ssh, cdrom_img, hostname, - node.get('user'), key_filename) + node.get('user'), key_filename, mac, ip) @mock.patch.object(os, 'access', return_value=False) def test_create_snapshot_qemu_no_image_local(self, mock_os_access): diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py index 1a2407575..6cc8b11f3 100644 --- a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py +++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py @@ -418,7 +418,8 @@ class OvsDpdkContextTestCase(unittest.TestCase): self.ovs_dpdk.configure_nics_for_ovs_dpdk = mock.Mock(return_value="") self.ovs_dpdk._name_task_id = 'fake_name' xml_str = 'vm-0' - mock_build_xml.return_value = (xml_str, '00:00:00:00:00:01') + self.ovs_dpdk.mac = '00:00:00:00:00:01' + mock_build_xml.return_value = (xml_str, self.ovs_dpdk.mac) self.ovs_dpdk._enable_interfaces = mock.Mock(return_value=xml_str) vnf_instance = mock.Mock() vnf_instance_2 = mock.Mock() @@ -439,7 +440,8 @@ class OvsDpdkContextTestCase(unittest.TestCase): vnf_instance, xml_str, self.ovs_dpdk._name_task_id, - self.ovs_dpdk.file_path) + self.ovs_dpdk.file_path, + self.ovs_dpdk.mac) @mock.patch.object(io, 'BytesIO') def test__check_hugepages(self, mock_bytesio): diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py index ae8e95f9a..316aca72a 100644 --- a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py +++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py @@ -301,8 +301,9 @@ class SriovContextTestCase(unittest.TestCase): self.sriov._name_task_id = 'fake_name' cfg = '/tmp/vm_sriov_0.xml' vm_name = 'vm-0' + mac = '00:00:00:00:00:01' xml_out = mock.Mock() - mock_build_vm_xml.return_value = (xml_out, '00:00:00:00:00:01') + mock_build_vm_xml.return_value = (xml_out, mac) mock_check_update_key.return_value = 'node_2' cdrom_img = '/var/lib/libvirt/images/cdrom-0.img' @@ -314,7 +315,8 @@ class SriovContextTestCase(unittest.TestCase): return_value='node_1') nodes_out = self.sriov.setup_sriov_context() mock_check_update_key.assert_called_once_with(connection, 'node_1', vm_name, - self.sriov._name_task_id, cdrom_img) + self.sriov._name_task_id, cdrom_img, + mac) self.assertEqual(['node_2'], nodes_out) mock_vnf_node.generate_vnf_instance.assert_called_once_with( 'flavor', 'networks', '1.2.3.4', 'vnf_0', |