Пример #1
0
def _api_to_environment(api_dict, want_solution_stack = False):
    # Convert solution_stack and tier to objects
    try:
        if want_solution_stack:
            solution_stack_name = api_dict['SolutionStackName']
            platform = SolutionStack(solution_stack_name)
        else:
            platform_arn = api_dict['PlatformArn']
            platform = PlatformVersion(platform_arn)
    except KeyError:
        platform = SolutionStack(api_dict['SolutionStackName'])

    tier = api_dict['Tier']
    tier = Tier(tier['Name'], tier['Type'], tier['Version'])

    env = Environment(
        version_label=api_dict.get('VersionLabel'),
        status=api_dict.get('Status'),
        app_name=api_dict.get('ApplicationName'),
        health=api_dict.get('Health'),
        id=api_dict.get('EnvironmentId'),
        date_updated=api_dict.get('DateUpdated'),
        platform=platform,
        description=api_dict.get('Description'),
        name=api_dict.get('EnvironmentName'),
        date_created=api_dict.get('DateCreated'),
        tier=tier,
        cname=api_dict.get('CNAME', 'UNKNOWN'),
        option_settings=api_dict.get('OptionSettings'),
        is_abortable=api_dict.get('AbortableOperationInProgress', False),
        environment_links=api_dict.get('EnvironmentLinks'),
        environment_arn=api_dict.get('EnvironmentArn')
    )
    return env
    def test_retrieve_application_version_url__app_version_url_not_found_in_app_source__raises_not_found_error(
            self, get_template_mock, wait_until_stack_exists_mock,
            get_environment_mock):
        io._log_warning = io.log_warning
        io.log_warning = mock.MagicMock()

        get_template_response = {
            "TemplateBody": {
                "Parameters": {
                    "AppSource": {
                        "NoEcho": "true",
                        "Type": "String",
                        "Description": "The url of the application source."
                    }
                },
                "Description":
                "AWS Elastic Beanstalk environment (Name: 'my_env_name'  Id: 'my_env_id')",
            }
        }

        get_environment_mock.return_value = Environment(name='my_env_name',
                                                        id='my_env_id')
        get_template_mock.return_value = get_template_response

        createops.retrieve_application_version_url('my_env_name')

        io.log_warning.assert_called_with(
            'Cannot find app source for environment. ')

        io.log_warning = io._log_warning
    def test_retrieve_application_version_url__successfully_returns_sample_app_url(
            self, get_template_mock, wait_until_stack_exists_mock,
            get_environment_mock):
        get_template_response = {
            "TemplateBody": {
                "Parameters": {
                    "AppSource": {
                        "NoEcho": "true",
                        "Type": "String",
                        "Description": "The url of the application source.",
                        "Default":
                        "http://sample-app-location/python-sample.zip"
                    },
                },
                "Description":
                "AWS Elastic Beanstalk environment (Name: 'my_env_name'  Id: 'my_env_id')",
            }
        }
        get_environment_mock.return_value = Environment(name='my_env_name',
                                                        id='my_env_id')
        get_template_mock.return_value = get_template_response

        self.assertEqual(
            "http://sample-app-location/python-sample.zip",
            createops.retrieve_application_version_url('my_env_name'))
    def test_retrieve_application_version_url__empty_response__raises_not_found_error(
            self, get_template_mock, wait_until_stack_exists_mock,
            get_environment_mock):
        get_template_response = {}

        io._log_warning = io.log_warning
        io.log_warning = mock.MagicMock()

        get_environment_mock.return_value = Environment(name='my_env_name',
                                                        id='my_env_id')
        get_template_mock.return_value = get_template_response
Пример #5
0
    def test_check_env_lifecycle_state(
        self,
        alert_environment_status_mock,
        get_environment_mock,
    ):
        environment_name = 'environment-1'
        environment = Environment(name=environment_name)
        get_environment_mock.return_value = environment

        deploy._check_env_lifecycle_state(env_name=environment_name)

        get_environment_mock.assert_called_once_with(env_name=environment_name)
        alert_environment_status_mock.assert_called_once_with(environment)
Пример #6
0
    def setUp(self):
        self.patcher_elasticbeanstalk = mock.patch(
            'ebcli.operations.appversionops.elasticbeanstalk')
        self.patcher_io = mock.patch('ebcli.operations.appversionops.io')
        self.mock_elasticbeanstalk = self.patcher_elasticbeanstalk.start()
        self.mock_io = self.patcher_io.start()

        self.mock_elasticbeanstalk.get_application_versions.return_value = {
            u'ApplicationVersions': [{
                u'ApplicationName': self.app_name,
                u'VersionLabel': self.version_to_delete
            }, {
                u'ApplicationName': self.app_name,
                u'VersionLabel': self.version_deployed
            }]
        }
        self.mock_elasticbeanstalk.get_app_environments.return_value = \
            [Environment(version_label=self.version_deployed, app_name=self.app_name, name='wow')]
Пример #7
0
class TestRestoreEnvironment(unittest.TestCase):
    current_time = datetime.now()
    request_id = 'foo-request-id'
    env_id = 'e-1234567890'
    app = Application(name="some-app")
    env1 = {'EnvironmnetId': env_id, 'EnvironmentName': "env1", 'VersionLabel': "v1",
            'ApplicationName': "app1", 'Status' : 'Ready',
            'DateUpdated': (date.today() - timedelta(days=10))}
    env2 = {'EnvironmnetId': 'e-0987654321', 'EnvironmentName': "env2", 'VersionLabel': "v2",
            'ApplicationName': "some-app", 'Status': 'Terminated',
            'DateUpdated': (date.today())}
    env_object = Environment(id=env_id, name="env1", version_label="v1", app_name="app1",
                       date_updated=(date.today() - timedelta(days=10)), status='Terminated')

    def setUp(self):
        self.patcher_beanstalk = mock.patch('ebcli.operations.restoreops.elasticbeanstalk')
        self.mock_beanstalk = self.patcher_beanstalk.start()
        self.env_object.status = 'Terminated'

    def tearDown(self):
        self.patcher_beanstalk.stop()

    def test_validate_restore_bad_env(self):
        self.env_object.status = 'Ready'
        self.mock_beanstalk.get_environment.return_value = self.env_object
        self.assertRaises(InvalidParameterValueError, restoreops.validate_restore, self.env_id)

    @mock.patch('ebcli.operations.restoreops.get_date_cutoff')
    def test_validate_restore_good_env(self, mock_date):
        mock_date.return_value = self.current_time
        self.mock_beanstalk.get_environment.return_value = self.env_object
        restoreops.validate_restore(self.env_id)
        self.mock_beanstalk.get_environment.assert_called_with(env_id=self.env_id, include_deleted=True,
                                               deleted_back_to=self.current_time)

    @mock.patch('ebcli.operations.restoreops.commonops')
    def test_restore_with_good_env(self, mock_common_ops):
        self.mock_beanstalk.get_environment.return_value = self.env_object
        self.mock_beanstalk.rebuild_environment.return_value = self.request_id

        restoreops.restore(self.env_id)

        mock_common_ops.wait_for_success_events.assert_called_with(self.request_id, timeout_in_minutes=None,
                                                                   can_abort=True)

    def test_restore_with_bad_param_exception(self):
        self.env_object.status = 'Ready'
        self.mock_beanstalk.get_environment.return_value = self.env_object

        self.mock_beanstalk.rebuild_environment.side_effect = [
            InvalidParameterValueError('Could not rebuild environment some-name because the cname is taken')]

        self.assertRaises(InvalidParameterValueError, restoreops.restore, self.env_id)


    def test_fetch_restorable_envs(self):
        self.mock_beanstalk.get_raw_app_environments.return_value = [self.env1, self.env2]

        environments = restoreops.get_restorable_envs(self.app)

        self.assertNotIn(self.env1, environments,
                         "Non-terminated environment returned in restorable environments when it should not be")
        self.assertIn(self.env2, environments, "Terminated environment not in restorable environments when it should be")