def test_generate_overcloudrc(self): stack = mock.MagicMock() stack.stack_name = 'overcast' stack.to_dict.return_value = { "outputs": [ { 'output_key': 'KeystoneURL', 'output_value': 'http://foo.com:8000/' }, { 'output_key': 'EndpointMap', 'output_value': { 'KeystoneAdmin': { 'host': 'fd00::1' } } }, ] } result = overcloudrc.create_overcloudrc(stack, "", "AdminPassword") self.assertIn("OS_PASSWORD=AdminPassword", result['overcloudrc']) self.assertIn("OS_PASSWORD=AdminPassword", result['overcloudrc.v3']) self.assertIn("OS_IDENTITY_API_VERSION=3", result['overcloudrc']) self.assertIn("OS_IDENTITY_API_VERSION=3", result['overcloudrc.v3']) self.assertIn(overcloudrc.CLOUDPROMPT, result['overcloudrc']) self.assertIn(overcloudrc.CLOUDPROMPT, result['overcloudrc.v3']) self.assertIn("OS_AUTH_TYPE=password", result['overcloudrc']) self.assertIn("OS_AUTH_TYPE=password", result['overcloudrc.v3'])
def run(self, context): orchestration_client = self.get_orchestration_client(context) swift = self.get_object_client(context) try: stack = orchestration_client.stacks.get(self.container) except heat_exc.HTTPNotFound: error = ( "The Heat stack {} could not be found. Make sure you have " "deployed before calling this action.").format(self.container) return actions.Result(error=error) # We need to check parameter_defaults first for a user provided # password. If that doesn't exist, we then should look in the # automatically generated passwords. # TODO(d0ugal): Abstract this operation somewhere. We shouldn't need to # know about the structure of the environment to get a password. try: env = plan_utils.get_env(swift, self.container) except swiftexceptions.ClientException as err: err_msg = ("Error retrieving environment for plan %s: %s" % (self.container, err)) LOG.error(err_msg) return actions.Result(error=err_msg) try: parameter_defaults = env['parameter_defaults'] passwords = env['passwords'] admin_pass = parameter_defaults.get('AdminPassword') if admin_pass is None: admin_pass = passwords['AdminPassword'] except KeyError: error = ("Unable to find the AdminPassword in the plan " "environment.") return actions.Result(error=error) region_name = parameter_defaults.get('KeystoneRegion') return overcloudrc.create_overcloudrc(stack, self.no_proxy, admin_pass, region_name)
def run(self, context): orchestration_client = self.get_orchestration_client(context) swift = self.get_object_client(context) try: stack = orchestration_client.stacks.get(self.container) except heat_exc.HTTPNotFound: error = ( "The Heat stack {} could not be found. Make sure you have " "deployed before calling this action.").format(self.container) return actions.Result(error=error) # We need to check parameter_defaults first for a user provided # password. If that doesn't exist, we then should look in the # automatically generated passwords. # TODO(d0ugal): Abstract this operation somewhere. We shouldn't need to # know about the structure of the environment to get a password. try: env = plan_utils.get_env(swift, self.container) except swiftexceptions.ClientException as err: err_msg = ("Error retrieving environment for plan %s: %s" % ( self.container, err)) LOG.error(err_msg) return actions.Result(error=err_msg) try: parameter_defaults = env['parameter_defaults'] passwords = env['passwords'] admin_pass = parameter_defaults.get('AdminPassword') if admin_pass is None: admin_pass = passwords['AdminPassword'] except KeyError: error = ("Unable to find the AdminPassword in the plan " "environment.") return actions.Result(error=error) region_name = parameter_defaults.get('KeystoneRegion') return overcloudrc.create_overcloudrc(stack, self.no_proxy, admin_pass, region_name)
def run_module(): result = dict(success=False, error="", overcloudrc="") argument_spec = openstack_full_argument_spec( **yaml.safe_load(DOCUMENTATION)['options']) module = AnsibleModule(argument_spec, supports_check_mode=True, **openstack_module_kwargs()) try: container = module.params.get('container') no_proxy = module.params.get('no_proxy') _, conn = openstack_cloud_from_module(module) tripleo = tc.TripleOCommon(session=conn.session) # if the user is working with this module in only check mode we do not # want to make any changes to the environment, just return the current # state with no modifications if module.check_mode: module.exit_json(**result) swift = tripleo.get_object_client() heat = tripleo.get_orchestration_client() overcloudrc = rc_utils.create_overcloudrc(swift, heat, container, no_proxy) result['overcloudrc'] = overcloudrc['overcloudrc'] result['success'] = True except Exception as err: result['error'] = str(err) result['msg'] = ("Error generating overcloudrc for plan %s: %s" % (container, err)) module.fail_json(**result) # in the event of a successful module execution, you will want to # simple AnsibleModule.exit_json(), passing the key/value results module.exit_json(**result)
def test_generate_overcloudrc(self): stack = mock.MagicMock() stack.stack_name = 'overcast' stack.to_dict.return_value = { "outputs": [ {'output_key': 'KeystoneURL', 'output_value': 'http://foo.com:8000/'}, {'output_key': 'EndpointMap', 'output_value': {'KeystoneAdmin': {'host': 'fd00::1'}}}, ] } result = overcloudrc.create_overcloudrc(stack, "", "AdminPassword") self.assertIn("OS_PASSWORD=AdminPassword", result['overcloudrc']) self.assertIn("OS_PASSWORD=AdminPassword", result['overcloudrc.v3']) self.assertNotIn("OS_IDENTITY_API_VERSION=3", result['overcloudrc']) self.assertIn("OS_IDENTITY_API_VERSION=3", result['overcloudrc.v3']) self.assertIn(overcloudrc.CLOUDPROMPT, result['overcloudrc']) self.assertIn(overcloudrc.CLOUDPROMPT, result['overcloudrc.v3']) self.assertIn("OS_AUTH_TYPE=password", result['overcloudrc']) self.assertIn("OS_AUTH_TYPE=password", result['overcloudrc.v3'])
def run(self): orchestration_client = self.get_orchestration_client() workflow_client = self.get_workflow_client() try: stack = orchestration_client.stacks.get(self.container) except heat_exc.HTTPNotFound: error = ( "The Heat stack {} could not be found. Make sure you have " "deployed before calling this action.").format(self.container) return mistral_workflow_utils.Result(error=error) try: environment = workflow_client.environments.get(self.container) except mistralclient_exc.APIException: error = "The Mistral environment {} could not be found.".format( self.container) return mistral_workflow_utils.Result(error=error) # We need to check parameter_defaults first for a user provided # password. If that doesn't exist, we then should look in the # automatically generated passwords. # TODO(d0ugal): Abstract this operation somewhere. We shouldn't need to # know about the structure of the environment to get a password. try: parameter_defaults = environment.variables['parameter_defaults'] passwords = environment.variables['passwords'] admin_pass = parameter_defaults.get('AdminPassword') if admin_pass is None: admin_pass = passwords['AdminPassword'] except KeyError: error = ("Unable to find the AdminPassword in the Mistral " "environment.") return mistral_workflow_utils.Result(error=error) return overcloudrc.create_overcloudrc(stack, self.no_proxy, admin_pass)
def test_generate_overcloudrc(self): stack = mock.MagicMock() stack.stack_name = 'overcast' stack.to_dict.return_value = { "outputs": [ { 'output_key': 'KeystoneURL', 'output_value': 'http://foo.com:8000/' }, { 'output_key': 'EndpointMap', 'output_value': { 'KeystoneAdmin': { 'host': 'fd00::1' } } }, ] } result = overcloudrc.create_overcloudrc(stack, "foo", "AdminPassword", "regionTwo") self.assertIn("export no_proxy='foo,foo.com,[fd00::1]'", result['overcloudrc']) self.assertIn("OS_PASSWORD=AdminPassword", result['overcloudrc']) self.assertIn("export PYTHONWARNINGS='ignore:Certificate", result['overcloudrc']) self.assertIn("OS_IDENTITY_API_VERSION=3", result['overcloudrc']) self.assertIn(overcloudrc.CLOUDPROMPT, result['overcloudrc']) self.assertIn("OS_AUTH_TYPE=password", result['overcloudrc']) self.assertIn("OS_AUTH_URL=http://foo.com:8000/", result['overcloudrc']) self.assertIn("OS_REGION_NAME=regionTwo", result['overcloudrc'])