From c69612e16707a4bbe440b95fcfc5996802b8f06c Mon Sep 17 00:00:00 2001 From: Proskurin Kirill Date: Tue, 26 Jul 2016 16:59:21 +0200 Subject: [PATCH] Add openrc creation per deployment Change-Id: If8731e7f9fb6baf0a6c1bc939524ae6729abba6c --- .gitignore | 3 +++ fuel_ccp/deploy.py | 17 +++++++++++++++++ fuel_ccp/tests/test_deploy.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/.gitignore b/.gitignore index e3ce9937..53bfd00f 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ ChangeLog # Configs *.conf + +# openrc files +openrc-* diff --git a/fuel_ccp/deploy.py b/fuel_ccp/deploy.py index 96f1ed70..b243488e 100644 --- a/fuel_ccp/deploy.py +++ b/fuel_ccp/deploy.py @@ -281,6 +281,21 @@ def _create_namespace(namespace): body={"metadata": {"name": namespace}}) +def _create_openrc(config, namespace): + openrc = ["export OS_PROJECT_DOMAIN_NAME=default", + "export OS_USER_DOMAIN_NAME=default", + "export OS_PROJECT_NAME=%s" % config['openstack_project_name'], + "export OS_USERNAME=%s" % config['openstack_user_name'], + "export OS_PASSWORD=%s" % config['openstack_user_password'], + "export OS_IDENTITY_API_VERSION=3", + "export OS_AUTH_URL=http://keystone.%s.svc.cluster.local:%s/v3" % + (namespace, config['keystone_public_port'])] + with open('openrc-%s' % namespace, 'w') as openrc_file: + openrc_file.write("\n".join(openrc)) + LOG.info("Openrc file for this deployment created at %s/openrc-%s", + os.getcwd(), namespace) + + def deploy_components(components=None): if components is None: components = CONF.repositories.names @@ -294,3 +309,5 @@ def deploy_components(components=None): for component in components: deploy_component(component, config) + + _create_openrc(config, namespace) diff --git a/fuel_ccp/tests/test_deploy.py b/fuel_ccp/tests/test_deploy.py index e05ca2d6..b80fc522 100644 --- a/fuel_ccp/tests/test_deploy.py +++ b/fuel_ccp/tests/test_deploy.py @@ -1,3 +1,6 @@ +import filecmp +import os + import mock from oslo_config import cfg import yaml @@ -9,6 +12,10 @@ CONF = cfg.CONF class TestDeploy(base.TestCase): + def setUp(self): + super(TestDeploy, self).setUp() + self.namespace = "py27_test_delme" + def test_fill_cmd(self): workflow = {} cmd = { @@ -91,6 +98,33 @@ class TestDeploy(base.TestCase): } self.assertDictEqual(expected, service) + def test_create_openrc(self): + namespace = self.namespace + openrc_etalon_file = 'openrc-%s-etalon' % namespace + openrc_test_file = 'openrc-%s' % namespace + config = {"openstack_project_name": "admin", + "openstack_user_name": "admin", + "openstack_user_password": "password", + "keystone_public_port": 5000} + rc = ["export OS_PROJECT_DOMAIN_NAME=default", + "export OS_USER_DOMAIN_NAME=default", + "export OS_PROJECT_NAME=%s" % config['openstack_project_name'], + "export OS_USERNAME=%s" % config['openstack_user_name'], + "export OS_PASSWORD=%s" % config['openstack_user_password'], + "export OS_IDENTITY_API_VERSION=3", + "export OS_AUTH_URL=http://keystone.%s.svc.cluster.local:%s/v3" % + (namespace, config['keystone_public_port'])] + + with open(openrc_etalon_file, 'w') as openrc_file: + openrc_file.write("\n".join(rc)) + self.addCleanup(os.remove, openrc_etalon_file) + deploy._create_openrc(config, namespace) + self.addCleanup(os.remove, openrc_test_file) + result = filecmp.cmp(openrc_etalon_file, + openrc_test_file, + shallow=False) + self.assertTrue(result) + class TestDeployCreateService(base.TestCase): def setUp(self):