def test_run_validation(self, mock_execute, mock_download_validation, mock_get_object_client): swiftclient = mock.MagicMock(url='http://swift:8080/v1/AUTH_test') mock_get_object_client.return_value = swiftclient Ctx = namedtuple('Ctx', 'auth_uri user_name auth_token project_name') mock_ctx = Ctx( auth_uri='auth_uri', user_name='user_name', auth_token='auth_token', project_name='project_name' ) mock_execute.return_value = 'output' mock_download_validation.return_value = 'validation_path' result = validations.run_validation(mock_get_object_client(), 'validation', 'identity_file', 'plan', 'inputs_file', mock_ctx) self.assertEqual('output', result) mock_execute.assert_called_once_with( '/usr/bin/sudo', '-u', 'validations', 'OS_AUTH_URL=auth_uri', 'OS_USERNAME=user_name', 'OS_AUTH_TOKEN=auth_token', 'OS_TENANT_NAME=project_name', '/usr/bin/run-validation', '--inputs', 'inputs_file', 'validation_path', 'identity_file', 'plan' ) mock_download_validation.assert_called_once_with( mock_get_object_client(), 'plan', 'validation')
def test_run_validation(self, mock_execute, mock_find_validation): Ctx = namedtuple('Ctx', 'auth_uri user_name auth_token project_name') mock_ctx = Ctx( auth_uri='auth_uri', user_name='user_name', auth_token='auth_token', project_name='project_name' ) mock_execute.return_value = 'output' mock_find_validation.return_value = 'validation_path' result = validations.run_validation('validation', 'identity_file', 'plan', mock_ctx) self.assertEqual('output', result) mock_execute.assert_called_once_with( '/usr/bin/sudo', '-u', 'validations', 'OS_AUTH_URL=auth_uri', 'OS_USERNAME=user_name', 'OS_AUTH_TOKEN=auth_token', 'OS_TENANT_NAME=project_name', '/usr/bin/run-validation', 'validation_path', 'identity_file', 'plan' ) mock_find_validation.assert_called_once_with('validation')
def test_run_validation(self, mock_execute, mock_download_validation, mock_get_object_client): swiftclient = mock.MagicMock(url='http://swift:8080/v1/AUTH_test') mock_get_object_client.return_value = swiftclient Ctx = namedtuple('Ctx', 'auth_uri user_name auth_token project_name') mock_ctx = Ctx( auth_uri='auth_uri', user_name='user_name', auth_token='auth_token', project_name='project_name' ) mock_execute.return_value = 'output' mock_download_validation.return_value = 'validation_path' result = validations.run_validation(mock_get_object_client(), 'validation', 'identity_file', 'plan', 'inputs_file', mock_ctx) self.assertEqual('output', result) mock_execute.assert_called_once_with( '/usr/bin/sudo', '-u', 'validations', 'OS_AUTH_URL=auth_uri', 'OS_USERNAME=user_name', 'OS_AUTH_TOKEN=auth_token', 'OS_TENANT_NAME=project_name', '/usr/bin/run-validation', '--inputs', 'inputs_file', 'validation_path', 'identity_file', 'plan', '/usr/share/openstack-tripleo-validations' ) mock_download_validation.assert_called_once_with( mock_get_object_client(), 'plan', 'validation')
def run(self, context): mc = self.get_workflow_client(context) identity_file = None try: env = mc.environments.get('ssh_keys') private_key = env.variables['private_key'] identity_file = utils.write_identity_file(private_key) stdout, stderr = utils.run_validation(self.validation, identity_file, self.plan, context) return_value = {'stdout': stdout, 'stderr': stderr} mistral_result = {"data": return_value} except mistralclient_api.APIException as e: return_value = {'stdout': '', 'stderr': e.error_message} mistral_result = {"error": return_value} except ProcessExecutionError as e: return_value = {'stdout': e.stdout, 'stderr': e.stderr} # Indicates to Mistral there was a failure mistral_result = {"error": return_value} finally: if identity_file: utils.cleanup_identity_file(identity_file) return actions.Result(**mistral_result)
def test_run_validation(self, mock_execute, mock_find_validation): Ctx = namedtuple('Ctx', 'auth_uri user_name auth_token project_name') mock_ctx = Ctx(auth_uri='auth_uri', user_name='user_name', auth_token='auth_token', project_name='project_name') mock_execute.return_value = 'output' mock_find_validation.return_value = 'validation_path' result = validations.run_validation('validation', 'identity_file', 'plan', mock_ctx) self.assertEqual('output', result) mock_execute.assert_called_once_with( '/usr/bin/sudo', '-u', 'validations', 'OS_AUTH_URL=auth_uri', 'OS_USERNAME=user_name', 'OS_AUTH_TOKEN=auth_token', 'OS_TENANT_NAME=project_name', '/usr/bin/run-validation', 'validation_path', 'identity_file', 'plan') mock_find_validation.assert_called_once_with('validation')
def run(self, context): mc = self.get_workflow_client(context) swift = self.get_object_client(context) identity_file = None inputs_file = None # Make sure the ssh_keys environment exists try: env = mc.environments.get('ssh_keys') except Exception: workflow_env = { 'name': 'ssh_keys', 'description': 'SSH keys for TripleO validations', 'variables': password_utils.create_ssh_keypair() } env = mc.environments.create(**workflow_env) try: private_key = env.variables['private_key'] identity_file = utils.write_identity_file(private_key) inputs_file = utils.write_inputs_file(self.inputs) stdout, stderr = utils.run_validation(swift, self.validation, identity_file, self.plan, inputs_file, context) return_value = {'stdout': stdout, 'stderr': stderr} mistral_result = {"data": return_value} except mistralclient_api.APIException as e: return_value = {'stdout': '', 'stderr': e.error_message} mistral_result = {"error": return_value} except ProcessExecutionError as e: return_value = {'stdout': e.stdout, 'stderr': e.stderr} # Indicates to Mistral there was a failure mistral_result = {"error": return_value} finally: if identity_file: utils.cleanup_identity_file(identity_file) if inputs_file: utils.cleanup_inputs_file(inputs_file) return actions.Result(**mistral_result)
def run(self): mc = self.get_workflow_client() identity_file = None try: env = mc.environments.get('ssh_keys') private_key = env.variables['private_key'] identity_file = utils.write_identity_file(private_key) stdout, stderr = utils.run_validation(self.validation, identity_file, self.plan) return_value = {'stdout': stdout, 'stderr': stderr} mistral_result = {"data": return_value} except mistralclient_api.APIException as e: return_value = {'stdout': '', 'stderr': e.error_message} mistral_result = {"error": return_value} except ProcessExecutionError as e: return_value = {'stdout': e.stdout, 'stderr': e.stderr} # Indicates to Mistral there was a failure mistral_result = {"error": return_value} finally: if identity_file: utils.cleanup_identity_file(identity_file) return mistral_workflow_utils.Result(**mistral_result)