Пример #1
0
    def test_run(self, mock_get_object_client, mock_get_workflow_client,
                 mock_get_snmpd_readonly_user_password,
                 mock_get_orchestration_client, mock_cache):

        mock_get_snmpd_readonly_user_password.return_value = "TestPassword"
        mock_ctx = mock.MagicMock()

        swift = mock.MagicMock(url="http://test.com")
        mock_env = yaml.safe_dump(
            {
                'name': 'overcast',
                'temp_environment': 'temp_environment',
                'template': 'template',
                'environments': [{
                    u'path': u'environments/test.yaml'
                }],
            },
            default_flow_style=False)
        swift.get_object.return_value = ({}, mock_env)
        mock_get_object_client.return_value = swift

        mock_orchestration = mock.MagicMock()
        mock_orchestration.stacks.environment.return_value = {
            'parameter_defaults': {}
        }
        mock_get_orchestration_client.return_value = mock_orchestration

        action = parameters.GeneratePasswordsAction()
        result = action.run(mock_ctx)

        for password_param_name in constants.PASSWORD_PARAMETER_NAMES:
            self.assertTrue(password_param_name in result,
                            "%s is not in %s" % (password_param_name, result))
        mock_cache.assert_called_once_with(mock_ctx, "overcloud",
                                           "tripleo.parameters.get")
Пример #2
0
    def test_run(self, mock_ctx, mock_get_workflow_client,
                 mock_get_snmpd_readonly_user_password,
                 mock_get_orchestration_client, mock_cache):

        mock_get_snmpd_readonly_user_password.return_value = "TestPassword"

        mock_ctx.return_value = mock.MagicMock()
        mock_mistral = mock.MagicMock()
        mock_env = mock.MagicMock()
        mock_env.name = constants.DEFAULT_CONTAINER_NAME
        mock_env.variables = {
            'temp_environment': 'temp_environment',
            'template': 'template',
            'environments': [{
                u'path': u'environments/test.yaml'
            }],
        }
        mock_mistral.environments.get.return_value = mock_env
        mock_get_workflow_client.return_value = mock_mistral

        mock_orchestration = mock.MagicMock()
        mock_orchestration.stacks.environment.return_value = {
            'parameter_defaults': {}
        }
        mock_get_orchestration_client.return_value = mock_orchestration

        action = parameters.GeneratePasswordsAction()
        result = action.run()

        for password_param_name in constants.PASSWORD_PARAMETER_NAMES:
            self.assertTrue(password_param_name in result,
                            "%s is not in %s" % (password_param_name, result))
        mock_cache.assert_called_once_with("overcloud",
                                           "tripleo.parameters.get")
Пример #3
0
    def test_passwords_exist_in_heat(
            self, mock_get_object_client, mock_get_workflow_client,
            mock_get_snmpd_readonly_user_password, mock_fernet_keys_setup,
            mock_create_ssh_keypair, mock_get_orchestration_client,
            mock_cache):

        mock_get_snmpd_readonly_user_password.return_value = "TestPassword"
        mock_create_ssh_keypair.return_value = {
            'public_key': 'Foo',
            'private_key': 'Bar'
        }
        mock_fernet_keys_setup.return_value = {
            '/tmp/foo': {
                'content': 'Foo'
            },
            '/tmp/bar': {
                'content': 'Bar'
            }
        }

        existing_passwords = _EXISTING_PASSWORDS.copy()
        existing_passwords.pop("AdminPassword")

        mock_ctx = mock.MagicMock()
        swift = mock.MagicMock(url="http://test.com")
        mock_env = yaml.safe_dump(
            {
                'name': constants.DEFAULT_CONTAINER_NAME,
                'temp_environment': 'temp_environment',
                'template': 'template',
                'environments': [{
                    u'path': u'environments/test.yaml'
                }],
                'passwords': existing_passwords.copy()
            },
            default_flow_style=False)

        swift.get_object.return_value = ({}, mock_env)
        mock_get_object_client.return_value = swift

        mock_orchestration = mock.MagicMock()
        mock_orchestration.stacks.environment.return_value = {
            'parameter_defaults': {
                'AdminPassword': '******',
            }
        }
        mock_get_orchestration_client.return_value = mock_orchestration

        action = parameters.GeneratePasswordsAction()
        result = action.run(mock_ctx)

        existing_passwords["AdminPassword"] = "******"
        # ensure old passwords used and no new generation
        self.assertEqual(existing_passwords, result)
        mock_cache.assert_called_once_with(mock_ctx, "overcloud",
                                           "tripleo.parameters.get")
Пример #4
0
    def test_passwords_exist_in_heat(self, mock_ctx, mock_get_workflow_client,
                                     mock_get_snmpd_readonly_user_password,
                                     mock_create_ssh_keypair,
                                     mock_get_orchestration_client,
                                     mock_cache):

        mock_get_snmpd_readonly_user_password.return_value = "TestPassword"
        mock_create_ssh_keypair.return_value = {
            'public_key': 'Foo',
            'private_key': 'Bar'
        }

        existing_passwords = _EXISTING_PASSWORDS.copy()
        existing_passwords.pop("AdminPassword")

        mock_ctx.return_value = mock.MagicMock()
        mock_mistral = mock.MagicMock()
        mock_env = mock.MagicMock()
        mock_env.name = constants.DEFAULT_CONTAINER_NAME
        mock_env.variables = {
            'temp_environment': 'temp_environment',
            'template': 'template',
            'environments': [{
                u'path': u'environments/test.yaml'
            }],
            'passwords': existing_passwords.copy()
        }
        mock_mistral.environments.get.return_value = mock_env
        mock_get_workflow_client.return_value = mock_mistral

        mock_orchestration = mock.MagicMock()
        mock_orchestration.stacks.environment.return_value = {
            'parameter_defaults': {
                'AdminPassword': '******',
            }
        }
        mock_get_orchestration_client.return_value = mock_orchestration

        action = parameters.GeneratePasswordsAction()
        result = action.run()

        existing_passwords["AdminPassword"] = "******"
        # ensure old passwords used and no new generation
        self.assertEqual(existing_passwords, result)
        mock_cache.assert_called_once_with("overcloud",
                                           "tripleo.parameters.get")