summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-08-23 13:26:22 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-08-23 13:26:22 +0000
commit2c8892eff32dcd1b1c763a0f799076b0909a7392 (patch)
treebc502110820103a7e95a377766e05a9ec78e1779
parent057652b25f68dd4720dbc40e7919237d3888fb12 (diff)
parent39bcfa45da62a3126ad2a2290aaaa0670e8c5cb0 (diff)
Merge "Provide access to VM in Standalone context"
-rw-r--r--yardstick/benchmark/contexts/standalone/model.py102
-rw-r--r--yardstick/benchmark/contexts/standalone/ovs_dpdk.py25
-rw-r--r--yardstick/benchmark/contexts/standalone/sriov.py24
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_model.py102
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py32
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py28
6 files changed, 261 insertions, 52 deletions
diff --git a/yardstick/benchmark/contexts/standalone/model.py b/yardstick/benchmark/contexts/standalone/model.py
index ecddcbbe0..962cb48e2 100644
--- a/yardstick/benchmark/contexts/standalone/model.py
+++ b/yardstick/benchmark/contexts/standalone/model.py
@@ -89,6 +89,17 @@ VM_TEMPLATE = """
</devices>
</domain>
"""
+
+USER_DATA_TEMPLATE = """
+cat > {user_file} <<EOF
+#cloud-config
+preserve_hostname: false
+hostname: {host}
+users:
+{user_config}
+EOF
+"""
+
WAIT_FOR_BOOT = 30
@@ -268,7 +279,7 @@ class Libvirt(object):
return vm_image
@classmethod
- def build_vm_xml(cls, connection, flavor, vm_name, index):
+ def build_vm_xml(cls, connection, flavor, vm_name, index, cdrom_img):
"""Build the XML from the configuration parameters"""
memory = flavor.get('ram', '4096')
extra_spec = flavor.get('extra_specs', {})
@@ -293,6 +304,9 @@ class Libvirt(object):
socket=socket, threads=threads,
vm_image=image, cpuset=cpuset, cputune=cputune)
+ # Add CD-ROM device
+ vm_xml = Libvirt.add_cdrom(cdrom_img, vm_xml)
+
return vm_xml, mac
@staticmethod
@@ -320,6 +334,71 @@ class Libvirt(object):
et = ET.ElementTree(element=root)
et.write(file_name, encoding='utf-8', method='xml')
+ @classmethod
+ def add_cdrom(cls, file_path, xml_str):
+ """Add a CD-ROM disk XML node in 'devices' node
+
+ <devices>
+ <disk type='file' device='cdrom'>
+ <driver name='qemu' type='raw'/>
+ <source file='/var/lib/libvirt/images/data.img'/>
+ <target dev='hdb'/>
+ <readonly/>
+ </disk>
+ ...
+ </devices>
+ """
+
+ root = ET.fromstring(xml_str)
+ device = root.find('devices')
+
+ disk = ET.SubElement(device, 'disk')
+ disk.set('type', 'file')
+ disk.set('device', 'cdrom')
+
+ driver = ET.SubElement(disk, 'driver')
+ driver.set('name', 'qemu')
+ driver.set('type', 'raw')
+
+ source = ET.SubElement(disk, 'source')
+ source.set('file', file_path)
+
+ target = ET.SubElement(disk, 'target')
+ target.set('dev', 'hdb')
+
+ ET.SubElement(disk, 'readonly')
+ return ET.tostring(root)
+
+ @staticmethod
+ def gen_cdrom_image(connection, file_path, vm_name, vm_user, key_filename):
+ """Generate ISO image for CD-ROM """
+
+ user_config = [" - name: {user_name}",
+ " ssh_authorized_keys:",
+ " - {pub_key_str}"]
+ if vm_user != "root":
+ user_config.append(" sudo: ALL=(ALL) NOPASSWD:ALL")
+
+ meta_data = "/tmp/meta-data"
+ user_data = "/tmp/user-data"
+ with open(".".join([key_filename, "pub"]), "r") as pub_key_file:
+ pub_key_str = pub_key_file.read().rstrip()
+ user_conf = os.linesep.join(user_config).format(pub_key_str=pub_key_str, user_name=vm_user)
+
+ cmd_lst = [
+ "touch %s" % meta_data,
+ USER_DATA_TEMPLATE.format(user_file=user_data, host=vm_name, user_config=user_conf),
+ "genisoimage -output {0} -volid cidata -joliet -r {1} {2}".format(file_path,
+ meta_data,
+ user_data),
+ "rm {0} {1}".format(meta_data, user_data),
+ ]
+ for cmd in cmd_lst:
+ LOG.info(cmd)
+ status, _, error = connection.execute(cmd)
+ if status:
+ raise exceptions.LibvirtQemuImageCreateError(error=error)
+
class StandaloneContextHelper(object):
""" This class handles all the common code for standalone
@@ -331,7 +410,7 @@ class StandaloneContextHelper(object):
@staticmethod
def install_req_libs(connection, extra_pkgs=None):
extra_pkgs = extra_pkgs or []
- pkgs = ["qemu-kvm", "libvirt-bin", "bridge-utils", "numactl", "fping"]
+ pkgs = ["qemu-kvm", "libvirt-bin", "bridge-utils", "numactl", "fping", "genisoimage"]
pkgs.extend(extra_pkgs)
cmd_template = "dpkg-query -W --showformat='${Status}\\n' \"%s\"|grep 'ok installed'"
for pkg in pkgs:
@@ -457,6 +536,25 @@ class StandaloneContextHelper(object):
node["ip"] = ip
return nodes
+ @classmethod
+ def check_update_key(cls, connection, node, vm_name, id_name, cdrom_img):
+ # Generate public/private keys if private key file is not provided
+ user_name = node.get('user')
+ if not user_name:
+ node['user'] = 'root'
+ user_name = node.get('user')
+ if not node.get('key_filename'):
+ key_filename = ''.join(
+ [constants.YARDSTICK_ROOT_PATH,
+ 'yardstick/resources/files/yardstick_key-',
+ id_name])
+ ssh.SSH.gen_keys(key_filename)
+ node['key_filename'] = key_filename
+ # Update image with public key
+ key_filename = node.get('key_filename')
+ Libvirt.gen_cdrom_image(connection, cdrom_img, vm_name, user_name, key_filename)
+ return node
+
class Server(object):
""" This class handles geting vnf nodes
diff --git a/yardstick/benchmark/contexts/standalone/ovs_dpdk.py b/yardstick/benchmark/contexts/standalone/ovs_dpdk.py
index 88ad598c3..5891f798e 100644
--- a/yardstick/benchmark/contexts/standalone/ovs_dpdk.py
+++ b/yardstick/benchmark/contexts/standalone/ovs_dpdk.py
@@ -394,13 +394,14 @@ class OvsDpdkContext(base.Context):
for index, (key, vnf) in enumerate(collections.OrderedDict(
self.servers).items()):
cfg = '/tmp/vm_ovs_%d.xml' % index
- vm_name = "vm_%d" % index
+ vm_name = "vm-%d" % index
+ cdrom_img = "/var/lib/libvirt/images/cdrom-%d.img" % index
# 1. Check and delete VM if already exists
model.Libvirt.check_if_vm_exists_and_delete(vm_name,
self.connection)
xml_str, mac = model.Libvirt.build_vm_xml(
- self.connection, self.vm_flavor, vm_name, index)
+ self.connection, self.vm_flavor, vm_name, index, cdrom_img)
# 2: Cleanup already available VMs
for vfs in [vfs for vfs_name, vfs in vnf["network_ports"].items()
@@ -411,16 +412,24 @@ class OvsDpdkContext(base.Context):
model.Libvirt.write_file(cfg, xml_str)
self.connection.put(cfg, cfg)
+ node = self.vnf_node.generate_vnf_instance(self.vm_flavor,
+ self.networks,
+ self.host_mgmt.get('ip'),
+ key, vnf, mac)
+ # Generate public/private keys if password or private key file is not provided
+ node = model.StandaloneContextHelper.check_update_key(self.connection,
+ node,
+ vm_name,
+ self.name,
+ cdrom_img)
+
+ # store vnf node details
+ nodes.append(node)
+
# NOTE: launch through libvirt
LOG.info("virsh create ...")
model.Libvirt.virsh_create_vm(self.connection, cfg)
self.vm_names.append(vm_name)
- # build vnf node details
- nodes.append(self.vnf_node.generate_vnf_instance(self.vm_flavor,
- self.networks,
- self.host_mgmt.get('ip'),
- key, vnf, mac))
-
return nodes
diff --git a/yardstick/benchmark/contexts/standalone/sriov.py b/yardstick/benchmark/contexts/standalone/sriov.py
index 3da12a9a8..8d410b2f3 100644
--- a/yardstick/benchmark/contexts/standalone/sriov.py
+++ b/yardstick/benchmark/contexts/standalone/sriov.py
@@ -225,13 +225,14 @@ class SriovContext(base.Context):
for index, (key, vnf) in enumerate(collections.OrderedDict(
self.servers).items()):
cfg = '/tmp/vm_sriov_%s.xml' % str(index)
- vm_name = "vm_%s" % str(index)
+ vm_name = "vm-%s" % str(index)
+ cdrom_img = "/var/lib/libvirt/images/cdrom-%d.img" % index
# 1. Check and delete VM if already exists
model.Libvirt.check_if_vm_exists_and_delete(vm_name,
self.connection)
xml_str, mac = model.Libvirt.build_vm_xml(
- self.connection, self.vm_flavor, vm_name, index)
+ self.connection, self.vm_flavor, vm_name, index, cdrom_img)
# 2: Cleanup already available VMs
network_ports = collections.OrderedDict(
@@ -243,17 +244,26 @@ class SriovContext(base.Context):
model.Libvirt.write_file(cfg, xml_str)
self.connection.put(cfg, cfg)
+ node = self.vnf_node.generate_vnf_instance(self.vm_flavor,
+ self.networks,
+ self.host_mgmt.get('ip'),
+ key, vnf, mac)
+ # Generate public/private keys if password or private key file is not provided
+ node = model.StandaloneContextHelper.check_update_key(self.connection,
+ node,
+ vm_name,
+ self.name,
+ cdrom_img)
+
+ # store vnf node details
+ nodes.append(node)
+
# NOTE: launch through libvirt
LOG.info("virsh create ...")
model.Libvirt.virsh_create_vm(self.connection, cfg)
self.vm_names.append(vm_name)
- # build vnf node details
- nodes.append(self.vnf_node.generate_vnf_instance(
- self.vm_flavor, self.networks, self.host_mgmt.get('ip'),
- key, vnf, mac))
-
return nodes
def _get_vf_data(self, value, vfmac, pfif):
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
index 8ad581918..371e4ef36 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
@@ -46,6 +46,16 @@ XML_SAMPLE_INTERFACE = """<?xml version="1.0"?>
class ModelLibvirtTestCase(unittest.TestCase):
+ XML_STR = model.VM_TEMPLATE.format(
+ vm_name="vm_name",
+ random_uuid=uuid.uuid4(),
+ mac_addr="00:01:02:03:04:05",
+ memory=2048, vcpu=2, cpu=2,
+ numa_cpus=0 - 10,
+ socket=1, threads=1,
+ vm_image="/var/lib/libvirt/images/yardstick-nsb-image.img",
+ cpuset=2 - 10, cputune='')
+
def setUp(self):
self.pci_address_str = '0001:04:03.2'
self.pci_address = utils.PciAddress(self.pci_address_str)
@@ -66,34 +76,34 @@ class ModelLibvirtTestCase(unittest.TestCase):
ssh_mock.execute = mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
# NOTE(ralonsoh): this test doesn't cover function execution.
- model.Libvirt.check_if_vm_exists_and_delete("vm_0", ssh_mock)
+ model.Libvirt.check_if_vm_exists_and_delete('vm-0', ssh_mock)
def test_virsh_create_vm(self):
self.mock_ssh.execute = mock.Mock(return_value=(0, 0, 0))
- model.Libvirt.virsh_create_vm(self.mock_ssh, 'vm_0')
- self.mock_ssh.execute.assert_called_once_with('virsh create vm_0')
+ model.Libvirt.virsh_create_vm(self.mock_ssh, 'vm-0')
+ self.mock_ssh.execute.assert_called_once_with('virsh create vm-0')
def test_virsh_create_vm_error(self):
self.mock_ssh.execute = mock.Mock(return_value=(1, 0, 'error_create'))
with self.assertRaises(exceptions.LibvirtCreateError) as exc:
- model.Libvirt.virsh_create_vm(self.mock_ssh, 'vm_0')
+ model.Libvirt.virsh_create_vm(self.mock_ssh, 'vm-0')
self.assertEqual('Error creating the virtual machine. Error: '
'error_create.', str(exc.exception))
- self.mock_ssh.execute.assert_called_once_with('virsh create vm_0')
+ self.mock_ssh.execute.assert_called_once_with('virsh create vm-0')
def test_virsh_destroy_vm(self):
self.mock_ssh.execute = mock.Mock(return_value=(0, 0, 0))
- model.Libvirt.virsh_destroy_vm('vm_0', self.mock_ssh)
- self.mock_ssh.execute.assert_called_once_with('virsh destroy vm_0')
+ model.Libvirt.virsh_destroy_vm('vm-0', self.mock_ssh)
+ self.mock_ssh.execute.assert_called_once_with('virsh destroy vm-0')
@mock.patch.object(model, 'LOG')
def test_virsh_destroy_vm_error(self, mock_logger):
self.mock_ssh.execute = mock.Mock(return_value=(1, 0, 'error_destroy'))
mock_logger.warning = mock.Mock()
- model.Libvirt.virsh_destroy_vm('vm_0', self.mock_ssh)
+ model.Libvirt.virsh_destroy_vm('vm-0', self.mock_ssh)
mock_logger.warning.assert_called_once_with(
- 'Error destroying VM %s. Error: %s', 'vm_0', 'error_destroy')
- self.mock_ssh.execute.assert_called_once_with('virsh destroy vm_0')
+ 'Error destroying VM %s. Error: %s', 'vm-0', 'error_destroy')
+ self.mock_ssh.execute.assert_called_once_with('virsh destroy vm-0')
def test_add_interface_address(self):
xml = ElementTree.ElementTree(
@@ -171,6 +181,56 @@ class ModelLibvirtTestCase(unittest.TestCase):
self.assertEqual('0x' + vm_pci.split(':')[2].split('.')[1],
interface_address.get('function'))
+ def test_add_cdrom(self):
+ xml_input = copy.deepcopy(XML_SAMPLE)
+ xml_output = model.Libvirt.add_cdrom('/var/lib/libvirt/images/data.img', xml_input)
+
+ root = ElementTree.fromstring(xml_output)
+ et_out = ElementTree.ElementTree(element=root)
+ disk = et_out.find('devices').find('disk')
+ self.assertEqual('file', disk.get('type'))
+ self.assertEqual('cdrom', disk.get('device'))
+ driver = disk.find('driver')
+ self.assertEqual('qemu', driver.get('name'))
+ self.assertEqual('raw', driver.get('type'))
+ source = disk.find('source')
+ self.assertEqual('/var/lib/libvirt/images/data.img', source.get('file'))
+ target = disk.find('target')
+ self.assertEqual('hdb', target.get('dev'))
+ self.assertIsNotNone(disk.find('readonly'))
+
+ def test_gen_cdrom_image(self):
+ self.mock_ssh.execute = mock.Mock(return_value=(0, 0, 0))
+ root = ElementTree.fromstring(self.XML_STR)
+ hostname = root.find('name').text
+ meta_data = "/tmp/meta-data"
+ user_data = "/tmp/user-data"
+ file_path = "/tmp/cdrom-0.img"
+ key_filename = "id_rsa"
+ pub_key_str = "KEY"
+ user = 'root'
+ user_config = [" - name: {user_name}",
+ " ssh_authorized_keys:",
+ " - {pub_key_str}"]
+
+ user_conf = os.linesep.join(user_config).format(pub_key_str=pub_key_str, user_name=user)
+ with mock.patch('six.moves.builtins.open', mock.mock_open(read_data=pub_key_str),
+ 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)
+ mock_file.assert_called_with(".".join([key_filename, "pub"]), "r")
+ self.assertEqual(result, pub_key_str)
+
+ self.mock_ssh.execute.assert_has_calls([
+ 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("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))
+ ])
+
def test_create_snapshot_qemu(self):
self.mock_ssh.execute = mock.Mock(return_value=(0, 0, 0))
index = 1
@@ -211,6 +271,19 @@ class ModelLibvirtTestCase(unittest.TestCase):
self.mock_ssh.put_file.assert_called_once_with(base_image,
'/tmp/base_image')
+ @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'}
+ 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
+ model.StandaloneContextHelper.check_update_key(self.mock_ssh, node, hostname, id_name,
+ cdrom_img)
+ mock_gen_cdrom_image.assert_called_once_with(self.mock_ssh, cdrom_img, hostname,
+ node.get('user'), key_filename)
+
@mock.patch.object(os, 'access', return_value=False)
def test_create_snapshot_qemu_no_image_local(self, mock_os_access):
self.mock_ssh.execute = mock.Mock(side_effect=[(0, 0, 0), (1, 0, 0)])
@@ -253,18 +326,20 @@ class ModelLibvirtTestCase(unittest.TestCase):
mac = model.StandaloneContextHelper.get_mac_address(0x00)
_uuid = uuid.uuid4()
connection = mock.Mock()
+ cdrom_img = '/tmp/cdrom-0.img'
with mock.patch.object(model.StandaloneContextHelper,
'get_mac_address', return_value=mac) as \
mock_get_mac_address, \
mock.patch.object(uuid, 'uuid4', return_value=_uuid):
xml_out, mac = model.Libvirt.build_vm_xml(
- connection, flavor, 'vm_name', 100)
+ connection, flavor, 'vm_name', 100, cdrom_img)
xml_ref = model.VM_TEMPLATE.format(vm_name='vm_name',
random_uuid=_uuid, mac_addr=mac, memory='1024', vcpu='8', cpu='4',
numa_cpus='0-7', socket='3', threads='2',
vm_image='qemu_image', cpuset='4,5', cputune='cool')
- self.assertEqual(xml_ref, xml_out)
+ xml_ref = model.Libvirt.add_cdrom(cdrom_img, xml_ref)
+ self.assertEqual(xml_out, xml_ref)
mock_get_mac_address.assert_called_once_with(0x00)
mock_create_snapshot_qemu.assert_called_once_with(
connection, 100, 'images')
@@ -296,6 +371,7 @@ class ModelLibvirtTestCase(unittest.TestCase):
status = model.Libvirt.pin_vcpu_for_perf(ssh_mock, 4)
self.assertIsNotNone(status)
+
class StandaloneContextHelperTestCase(unittest.TestCase):
NODE_SAMPLE = "nodes_sample.yaml"
@@ -463,7 +539,7 @@ class ServerTestCase(unittest.TestCase):
}
}
status = self.server.generate_vnf_instance(
- {}, self.NETWORKS, '1.1.1.1/24', 'vm_0', vnf, '00:00:00:00:00:01')
+ {}, self.NETWORKS, '1.1.1.1/24', 'vm-0', vnf, '00:00:00:00:00:01')
self.assertIsNotNone(status)
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 69779d3e0..1a2407575 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
@@ -231,8 +231,8 @@ class OvsDpdkContextTestCase(unittest.TestCase):
def test_undeploy(self, mock_libvirt):
self.ovs_dpdk.vm_deploy = True
self.ovs_dpdk.connection = mock.Mock()
- self.ovs_dpdk.vm_names = ['vm_0', 'vm_1']
- self.ovs_dpdk.drivers = ['vm_0', 'vm_1']
+ self.ovs_dpdk.vm_names = ['vm-0', 'vm-1']
+ self.ovs_dpdk.drivers = ['vm-0', 'vm-1']
self.ovs_dpdk.cleanup_ovs_dpdk_env = mock.Mock()
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.undeploy()
@@ -370,7 +370,7 @@ class OvsDpdkContextTestCase(unittest.TestCase):
ssh.return_value = ssh_mock
self.ovs_dpdk.vm_deploy = True
self.ovs_dpdk.connection = ssh_mock
- self.ovs_dpdk.vm_names = ['vm_0', 'vm_1']
+ self.ovs_dpdk.vm_names = ['vm-0', 'vm-1']
self.ovs_dpdk.drivers = []
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.helper.get_mac_address = mock.Mock(return_value="")
@@ -381,7 +381,7 @@ class OvsDpdkContextTestCase(unittest.TestCase):
def test__enable_interfaces(self, mock_add_ovs_interface):
self.ovs_dpdk.vm_deploy = True
self.ovs_dpdk.connection = mock.Mock()
- self.ovs_dpdk.vm_names = ['vm_0', 'vm_1']
+ self.ovs_dpdk.vm_names = ['vm-0', 'vm-1']
self.ovs_dpdk.drivers = []
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.ovs_properties = {'vpath': 'fake_path'}
@@ -391,15 +391,16 @@ class OvsDpdkContextTestCase(unittest.TestCase):
'fake_path', 0, self.NETWORKS['private_0']['vpci'],
self.NETWORKS['private_0']['mac'], 'test')
+ @mock.patch.object(model.StandaloneContextHelper, 'check_update_key')
@mock.patch.object(model.Libvirt, 'write_file')
@mock.patch.object(model.Libvirt, 'build_vm_xml')
@mock.patch.object(model.Libvirt, 'check_if_vm_exists_and_delete')
@mock.patch.object(model.Libvirt, 'virsh_create_vm')
- def test_setup_ovs_dpdk_context(self, mock_create_vm, mock_check_if_exists,
- mock_build_xml, mock_write_file):
+ def test_setup_ovs_dpdk_context(self, mock_create_vm, mock_check_if_exists, mock_build_xml,
+ mock_write_file, mock_check_update_key):
self.ovs_dpdk.vm_deploy = True
self.ovs_dpdk.connection = mock.Mock()
- self.ovs_dpdk.vm_names = ['vm_0', 'vm_1']
+ self.ovs_dpdk.vm_names = ['vm-0', 'vm-1']
self.ovs_dpdk.drivers = []
self.ovs_dpdk.servers = {
'vnf_0': {
@@ -413,23 +414,32 @@ class OvsDpdkContextTestCase(unittest.TestCase):
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.host_mgmt = {}
self.ovs_dpdk.flavor = {}
+ self.ovs_dpdk.file_path = '/var/lib/libvirt/images/cdrom-0.img'
self.ovs_dpdk.configure_nics_for_ovs_dpdk = mock.Mock(return_value="")
- xml_str = mock.Mock()
+ 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._enable_interfaces = mock.Mock(return_value=xml_str)
vnf_instance = mock.Mock()
+ vnf_instance_2 = mock.Mock()
+ mock_check_update_key.return_value = vnf_instance_2
self.ovs_dpdk.vnf_node.generate_vnf_instance = mock.Mock(
return_value=vnf_instance)
- self.assertEqual([vnf_instance],
+ self.assertEqual([vnf_instance_2],
self.ovs_dpdk.setup_ovs_dpdk_context())
mock_create_vm.assert_called_once_with(
self.ovs_dpdk.connection, '/tmp/vm_ovs_0.xml')
mock_check_if_exists.assert_called_once_with(
- 'vm_0', self.ovs_dpdk.connection)
+ 'vm-0', self.ovs_dpdk.connection)
mock_build_xml.assert_called_once_with(
- self.ovs_dpdk.connection, self.ovs_dpdk.vm_flavor, 'vm_0', 0)
+ self.ovs_dpdk.connection, self.ovs_dpdk.vm_flavor, 'vm-0', 0, self.ovs_dpdk.file_path)
mock_write_file.assert_called_once_with('/tmp/vm_ovs_0.xml', xml_str)
+ mock_check_update_key.assert_called_once_with(self.ovs_dpdk.connection,
+ vnf_instance,
+ xml_str,
+ self.ovs_dpdk._name_task_id,
+ self.ovs_dpdk.file_path)
@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 74c31569c..ae8e95f9a 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py
@@ -113,8 +113,8 @@ class SriovContextTestCase(unittest.TestCase):
self.sriov.vm_deploy = True
self.sriov.connection = mock_ssh
- self.sriov.vm_names = ['vm_0', 'vm_1']
- self.sriov.drivers = ['vm_0', 'vm_1']
+ self.sriov.vm_names = ['vm-0', 'vm-1']
+ self.sriov.drivers = ['vm-0', 'vm-1']
self.assertIsNone(self.sriov.undeploy())
def _get_file_abspath(self, filename):
@@ -254,7 +254,7 @@ class SriovContextTestCase(unittest.TestCase):
ssh.return_value = ssh_mock
self.sriov.vm_deploy = True
self.sriov.connection = ssh_mock
- self.sriov.vm_names = ['vm_0', 'vm_1']
+ self.sriov.vm_names = ['vm-0', 'vm-1']
self.sriov.drivers = []
self.sriov.networks = self.NETWORKS
self.sriov.helper.get_mac_address = mock.Mock(return_value="")
@@ -267,7 +267,7 @@ class SriovContextTestCase(unittest.TestCase):
def test__enable_interfaces(self, mock_add_sriov, mock_ssh):
self.sriov.vm_deploy = True
self.sriov.connection = mock_ssh
- self.sriov.vm_names = ['vm_0', 'vm_1']
+ self.sriov.vm_names = ['vm-0', 'vm-1']
self.sriov.drivers = []
self.sriov.networks = self.NETWORKS
self.assertEqual(
@@ -276,12 +276,13 @@ class SriovContextTestCase(unittest.TestCase):
mock_add_sriov.assert_called_once_with(
'0000:00:0a.0', 0, self.NETWORKS['private_0']['mac'], 'test')
+ @mock.patch.object(model.StandaloneContextHelper, 'check_update_key')
@mock.patch.object(model.Libvirt, 'build_vm_xml')
@mock.patch.object(model.Libvirt, 'check_if_vm_exists_and_delete')
@mock.patch.object(model.Libvirt, 'write_file')
@mock.patch.object(model.Libvirt, 'virsh_create_vm')
- def test_setup_sriov_context(self, mock_create_vm, mock_write_file,
- mock_check, mock_build_vm_xml):
+ def test_setup_sriov_context(self, mock_create_vm, mock_write_file, mock_check,
+ mock_build_vm_xml, mock_check_update_key):
self.sriov.servers = {
'vnf_0': {
'network_ports': {
@@ -297,24 +298,29 @@ class SriovContextTestCase(unittest.TestCase):
self.sriov.vm_flavor = 'flavor'
self.sriov.networks = 'networks'
self.sriov.configure_nics_for_sriov = mock.Mock()
+ self.sriov._name_task_id = 'fake_name'
cfg = '/tmp/vm_sriov_0.xml'
- vm_name = 'vm_0'
+ vm_name = 'vm-0'
xml_out = mock.Mock()
mock_build_vm_xml.return_value = (xml_out, '00:00:00:00:00:01')
+ mock_check_update_key.return_value = 'node_2'
+ cdrom_img = '/var/lib/libvirt/images/cdrom-0.img'
with mock.patch.object(self.sriov, 'vnf_node') as mock_vnf_node, \
mock.patch.object(self.sriov, '_enable_interfaces') as \
mock_enable_interfaces:
mock_enable_interfaces.return_value = 'out_xml'
mock_vnf_node.generate_vnf_instance = mock.Mock(
- return_value='node')
+ return_value='node_1')
nodes_out = self.sriov.setup_sriov_context()
- self.assertEqual(['node'], nodes_out)
+ mock_check_update_key.assert_called_once_with(connection, 'node_1', vm_name,
+ self.sriov._name_task_id, cdrom_img)
+ self.assertEqual(['node_2'], nodes_out)
mock_vnf_node.generate_vnf_instance.assert_called_once_with(
'flavor', 'networks', '1.2.3.4', 'vnf_0',
self.sriov.servers['vnf_0'], '00:00:00:00:00:01')
mock_build_vm_xml.assert_called_once_with(
- connection, 'flavor', vm_name, 0)
+ connection, 'flavor', vm_name, 0, cdrom_img)
mock_create_vm.assert_called_once_with(connection, cfg)
mock_check.assert_called_once_with(vm_name, connection)
mock_write_file.assert_called_once_with(cfg, 'out_xml')
@@ -332,7 +338,7 @@ class SriovContextTestCase(unittest.TestCase):
ssh.return_value = ssh_mock
self.sriov.vm_deploy = True
self.sriov.connection = ssh_mock
- self.sriov.vm_names = ['vm_0', 'vm_1']
+ self.sriov.vm_names = ['vm-0', 'vm-1']
self.sriov.drivers = []
self.sriov.servers = {
'vnf_0': {