aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/contexts/standalone/model.py
diff options
context:
space:
mode:
authorStepan Andrushko <stepanx.andrushko@intel.com>2018-08-28 13:30:19 +0300
committerStepan Andrushko <stepanx.andrushko@intel.com>2018-08-29 20:27:00 +0300
commitc3a9c990edce2d393ae65b8090aae64a729b59d9 (patch)
tree0a45370436c04dc92bdd84199c3465a7314a555d /yardstick/benchmark/contexts/standalone/model.py
parent749a77816a4ecd1adee41f896c6e6fc779127046 (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/benchmark/contexts/standalone/model.py')
-rw-r--r--yardstick/benchmark/contexts/standalone/model.py42
1 files changed, 31 insertions, 11 deletions
diff --git a/yardstick/benchmark/contexts/standalone/model.py b/yardstick/benchmark/contexts/standalone/model.py
index 962cb48e2..fa78fc1eb 100644
--- a/yardstick/benchmark/contexts/standalone/model.py
+++ b/yardstick/benchmark/contexts/standalone/model.py
@@ -100,6 +100,19 @@ users:
EOF
"""
+NETWORK_DATA_TEMPLATE = """
+cat > {network_file} <<EOF
+#cloud-config
+version: 2
+ethernets:
+ ens3:
+ match:
+ mac_address: {mac_address}
+ addresses:
+ - {ip_address}
+EOF
+"""
+
WAIT_FOR_BOOT = 30
@@ -370,7 +383,7 @@ class Libvirt(object):
return ET.tostring(root)
@staticmethod
- def gen_cdrom_image(connection, file_path, vm_name, vm_user, key_filename):
+ def gen_cdrom_image(connection, file_path, vm_name, vm_user, key_filename, mac, ip):
"""Generate ISO image for CD-ROM """
user_config = [" - name: {user_name}",
@@ -381,6 +394,7 @@ class Libvirt(object):
meta_data = "/tmp/meta-data"
user_data = "/tmp/user-data"
+ network_data = "/tmp/network-config"
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)
@@ -388,10 +402,13 @@ class Libvirt(object):
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),
+ NETWORK_DATA_TEMPLATE.format(network_file=network_data, mac_address=mac,
+ ip_address=ip),
+ "genisoimage -output {0} -volid cidata -joliet -r {1} {2} {3}".format(file_path,
+ meta_data,
+ user_data,
+ network_data),
+ "rm {0} {1} {2}".format(meta_data, user_data, network_data),
]
for cmd in cmd_lst:
LOG.info(cmd)
@@ -537,7 +554,7 @@ class StandaloneContextHelper(object):
return nodes
@classmethod
- def check_update_key(cls, connection, node, vm_name, id_name, cdrom_img):
+ def check_update_key(cls, connection, node, vm_name, id_name, cdrom_img, mac):
# Generate public/private keys if private key file is not provided
user_name = node.get('user')
if not user_name:
@@ -552,7 +569,9 @@ class StandaloneContextHelper(object):
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)
+ ip_netmask = "{0}/{1}".format(node.get('ip'), node.get('netmask'))
+ Libvirt.gen_cdrom_image(connection, cdrom_img, vm_name, user_name, key_filename, mac,
+ ip_netmask)
return node
@@ -567,7 +586,7 @@ class Server(object):
for key, vfs in vnf["network_ports"].items():
if key == "mgmt":
- mgmtip = str(IPNetwork(vfs['cidr']).ip)
+ mgmt_cidr = IPNetwork(vfs['cidr'])
continue
vf = ports[vfs[0]]
@@ -584,14 +603,15 @@ class Server(object):
})
index = index + 1
- return mgmtip, interfaces
+ return mgmt_cidr, interfaces
@classmethod
def generate_vnf_instance(cls, flavor, ports, ip, key, vnf, mac):
- mgmtip, interfaces = cls.build_vnf_interfaces(vnf, ports)
+ mgmt_cidr, interfaces = cls.build_vnf_interfaces(vnf, ports)
result = {
- "ip": mgmtip,
+ "ip": str(mgmt_cidr.ip),
+ "netmask": str(mgmt_cidr.netmask),
"mac": mac,
"host": ip,
"user": flavor.get('user', 'root'),