diff options
Diffstat (limited to 'snaps/openstack/tests/openstack_tests.py')
-rw-r--r-- | snaps/openstack/tests/openstack_tests.py | 76 |
1 files changed, 68 insertions, 8 deletions
diff --git a/snaps/openstack/tests/openstack_tests.py b/snaps/openstack/tests/openstack_tests.py index 516d24d..f3a1df7 100644 --- a/snaps/openstack/tests/openstack_tests.py +++ b/snaps/openstack/tests/openstack_tests.py @@ -16,6 +16,7 @@ import logging import re from snaps import file_utils +from snaps.config.flavor import FlavorConfig from snaps.config.image import ImageConfig from snaps.config.network import NetworkConfig, SubnetConfig from snaps.config.router import RouterConfig @@ -312,22 +313,81 @@ def ubuntu_image_settings(name, url=None, image_metadata=None, public=public) -def get_priv_net_config(project_name, net_name, subnet_name, router_name=None, - cidr='10.55.0.0/24', external_net=None, - netconf_override=None): +def get_priv_net_config(project_name, net_name, mtu=None, subnet_name=None, + router_name=None, cidr='10.55.0.0/24', + external_net=None, netconf_override=None): return OSNetworkConfig( - project_name, net_name, subnet_name, cidr, router_name, + project_name, net_name, mtu, subnet_name, cidr, router_name, external_gateway=external_net, netconf_override=netconf_override) def get_pub_net_config( - project_name, net_name, subnet_name=None, router_name=None, + project_name, net_name, mtu=None, subnet_name=None, router_name=None, cidr='10.55.1.0/24', external_net=None, netconf_override=None): - return OSNetworkConfig(project_name, net_name, subnet_name, cidr, + return OSNetworkConfig(project_name, net_name, mtu, subnet_name, cidr, router_name, external_gateway=external_net, netconf_override=netconf_override) +def get_flavor_config(name, ram, disk, vcpus, ephemeral=None, swap=None, + rxtx_factor=None, is_public=None, metadata=None): + """This method replaces the hard coded basic element (e.g. ram, vcpu, disk + etc) with those are included in the new freeform dict() of metadata + parameter. + + :param name: the flavor name (required) + :param ram: memory in MB to allocate to VM (required) + :param disk: disk storage in GB (required) + :param vcpus: the number of CPUs to allocate to VM (required) + :param ephemeral: the size of the ephemeral disk in GB (default=0) + :param swap: the size of the swap disk in GB (default=0) + :param rxtx_factor: the receive/transmit factor to be set on ports + if backend supports QoS extension (default=1.0) + :param is_public: flag that denotes whether or not other projects + can access image (default=True) + :param metadata: - freeform dict() for special metadata (optional) + - freeform dict() for values of basic elements + (e.g. ram, vcpu, disk, etc) could be added. + As result the hard coded values of those elements will be + overwritten by the new ones (optional) + :return: The FlavorConfig replacing the hard coded basic element values + (e.g. ram, vcpu, disk etc) with those are included in the metadata + dict [optional]. The metadata parameter in the FlavorConfig + consist of the metadata data only. + """ + + metadata_excl = metadata + if metadata: + if 'ram' in metadata: + ram = metadata['ram'] + del metadata_excl['ram'] + if 'disk' in metadata: + disk = metadata['disk'] + del metadata_excl['disk'] + if 'vcpus' in metadata: + vcpus = metadata['vcpus'] + del metadata_excl['vcpus'] + if 'ephemeral' in metadata: + ephemeral = metadata['ephemeral'] + del metadata_excl['ephemeral'] + if 'swap' in metadata: + swap = metadata['swap'] + del metadata_excl['swap'] + if 'rxtx_factor' in metadata: + rxtx_factor = metadata['rxtx_factor'] + del metadata_excl['rxtx_factor'] + if 'is_public' in metadata: + is_public = metadata['is_public'] + del metadata_excl['is_public'] + if 'metadata' in metadata: + metadata_excl = metadata['metadata'] + + return FlavorConfig( + name=name, ram=ram, disk=disk, vcpus=vcpus, ephemeral=ephemeral, + swap=swap, rxtx_factor=rxtx_factor, is_public=is_public, + metadata=metadata_excl) + + class OSNetworkConfig: """ Represents the settings required for the creation of a network in OpenStack @@ -335,7 +395,7 @@ class OSNetworkConfig: physical_network and segmentation_id """ - def __init__(self, project_name, net_name, subnet_name=None, + def __init__(self, project_name, net_name, mtu=None, subnet_name=None, subnet_cidr=None, router_name=None, external_gateway=None, netconf_override=None): """ @@ -345,7 +405,7 @@ class OSNetworkConfig: """ if subnet_name and subnet_cidr: network_conf = NetworkConfig( - name=net_name, subnet_settings=[ + name=net_name, mtu=mtu, subnet_settings=[ SubnetConfig(cidr=subnet_cidr, name=subnet_name)]) else: network_conf = NetworkConfig(name=net_name) |