summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/tests/openstack_tests.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-02-15 09:13:54 -0700
committerspisarski <s.pisarski@cablelabs.com>2017-02-15 09:15:34 -0700
commit57777f3df521553a06cd01a3861b415d2905ceca (patch)
treef3b3be457baec7b5231309989aa3ffa9658cd25d /snaps/openstack/tests/openstack_tests.py
parent73ef791a1cde68e0d8d69cddf63534fbb90f3e2d (diff)
Initial patch with all code from CableLabs repository.
Change-Id: I70a2778718c5e7f21fd14e4ad28c9269d3761cc7 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/tests/openstack_tests.py')
-rw-r--r--snaps/openstack/tests/openstack_tests.py144
1 files changed, 144 insertions, 0 deletions
diff --git a/snaps/openstack/tests/openstack_tests.py b/snaps/openstack/tests/openstack_tests.py
new file mode 100644
index 0000000..dab2ea2
--- /dev/null
+++ b/snaps/openstack/tests/openstack_tests.py
@@ -0,0 +1,144 @@
+# Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs")
+# and others. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import re
+
+from snaps import file_utils
+from snaps.openstack.create_network import NetworkSettings, SubnetSettings
+from snaps.openstack.create_router import RouterSettings
+from snaps.openstack.os_credentials import OSCreds, ProxySettings
+from snaps.openstack.create_image import ImageSettings
+import logging
+
+__author__ = 'spisarski'
+
+
+logger = logging.getLogger('openstack_tests')
+
+
+def get_credentials(os_env_file=None, proxy_settings_str=None, ssh_proxy_cmd=None, dev_os_env_file=None):
+ """
+ Returns the OpenStack credentials object. It first attempts to retrieve them from a standard OpenStack source file.
+ If that file is None, it will attempt to retrieve them with a YAML file.
+ it will retrieve them from a
+ :param os_env_file: the OpenStack source file
+ :param proxy_settings_str: proxy settings string <host>:<port> (optional)
+ :param ssh_proxy_cmd: the SSH proxy command for your environment (optional)
+ :param dev_os_env_file: the YAML file to retrieve both the OS credentials and proxy settings
+ :return: the SNAPS credentials object
+ """
+ if os_env_file:
+ logger.debug('Reading RC file - ' + os_env_file)
+ config = file_utils.read_os_env_file(os_env_file)
+ proj_name = config.get('OS_PROJECT_NAME')
+ if not proj_name:
+ proj_name = config.get('OS_TENANT_NAME')
+
+ proj_domain_id = 'default'
+ user_domain_id = 'default'
+
+ if config.get('OS_PROJECT_DOMAIN_ID'):
+ proj_domain_id = config['OS_PROJECT_DOMAIN_ID']
+ if config.get('OS_USER_DOMAIN_ID'):
+ user_domain_id = config['OS_USER_DOMAIN_ID']
+ if config.get('OS_IDENTITY_API_VERSION'):
+ version = int(config['OS_IDENTITY_API_VERSION'])
+ else:
+ version = 2
+
+ proxy_settings = None
+ if proxy_settings_str:
+ tokens = re.split(':', proxy_settings_str)
+ proxy_settings = ProxySettings(tokens[0], tokens[1], ssh_proxy_cmd)
+
+ os_creds = OSCreds(username=config['OS_USERNAME'],
+ password=config['OS_PASSWORD'],
+ auth_url=config['OS_AUTH_URL'],
+ project_name=proj_name,
+ identity_api_version=version,
+ user_domain_id=user_domain_id,
+ project_domain_id=proj_domain_id,
+ proxy_settings=proxy_settings)
+ else:
+ logger.info('Reading development os_env file - ' + dev_os_env_file)
+ config = file_utils.read_yaml(dev_os_env_file)
+ identity_api_version = config.get('identity_api_version')
+ if not identity_api_version:
+ identity_api_version = 2
+
+ proxy_settings = None
+ proxy_str = config.get('http_proxy')
+ if proxy_str:
+ tokens = re.split(':', proxy_str)
+ proxy_settings = ProxySettings(tokens[0], tokens[1], config.get('ssh_proxy_cmd'))
+
+ os_creds = OSCreds(username=config['username'], password=config['password'],
+ auth_url=config['os_auth_url'], project_name=config['project_name'],
+ identity_api_version=identity_api_version,
+ proxy_settings=proxy_settings)
+
+ logger.info('OS Credentials = ' + str(os_creds))
+ return os_creds
+
+
+def cirros_url_image(name):
+ return ImageSettings(name=name, image_user='cirros', img_format='qcow2',
+ url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img')
+
+
+def file_image_test_settings(name, file_path):
+ return ImageSettings(name=name, image_user='cirros', img_format='qcow2',
+ image_file=file_path)
+
+
+def centos_url_image(name):
+ return ImageSettings(name=name, image_user='centos', img_format='qcow2',
+ url='http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2',
+ nic_config_pb_loc='./provisioning/ansible/centos-network-setup/playbooks/configure_host.yml')
+
+
+def ubuntu_url_image(name):
+ return ImageSettings(
+ name=name, image_user='ubuntu', img_format='qcow2',
+ url='http://uec-images.ubuntu.com/releases/trusty/14.04/ubuntu-14.04-server-cloudimg-amd64-disk1.img',
+ nic_config_pb_loc='./provisioning/ansible/ubuntu-network-setup/playbooks/configure_host.yml')
+
+
+def get_priv_net_config(net_name, subnet_name, router_name=None, cidr='10.55.0.0/24', external_net=None):
+ return OSNetworkConfig(net_name, subnet_name, cidr, router_name, external_gateway=external_net)
+
+
+def get_pub_net_config(net_name, subnet_name=None, router_name=None, cidr='10.55.1.0/24', external_net=None):
+ return OSNetworkConfig(net_name, subnet_name, cidr, router_name, external_gateway=external_net)
+
+
+class OSNetworkConfig:
+ """
+ Represents the settings required for the creation of a network in OpenStack
+ """
+
+ def __init__(self, net_name, subnet_name=None, subnet_cidr=None, router_name=None, external_gateway=None):
+
+ if subnet_name and subnet_cidr:
+ self.network_settings = NetworkSettings(
+ name=net_name, subnet_settings=[SubnetSettings(cidr=subnet_cidr, name=subnet_name)])
+ else:
+ self.network_settings = NetworkSettings(name=net_name)
+
+ if router_name:
+ if subnet_name:
+ self.router_settings = RouterSettings(name=router_name, external_gateway=external_gateway,
+ internal_subnets=[subnet_name])
+ else:
+ self.router_settings = RouterSettings(name=router_name, external_gateway=external_gateway)