def test_status__verbose_mode__elbv2(
            self, get_target_group_healths_mock,
            get_target_groups_for_load_balancer_mock,
            get_environment_resources_mock, get_default_repository_mock,
            get_default_branch_mock, echo_mock, log_alert_mock,
            find_solution_stack_from_string_mock, get_environment_mock):
        environment_object = Environment.json_to_environment_object(
            mock_responses.DESCRIBE_ENVIRONMENTS_RESPONSE['Environments'][0])
        environment_object.platform = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
        )
        get_environment_mock.return_value = environment_object
        find_solution_stack_from_string_mock.return_value = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
        )
        get_default_branch_mock.return_value = 'branch'
        get_default_repository_mock.return_value = 'repository'
        get_environment_resources_mock.return_value = mock_responses.DESCRIBE_ENVIRONMENT_RESOURCES_RESPONSE__ELBV2_ENVIRONMENT
        get_target_groups_for_load_balancer_mock.return_value = mock_responses.DESCRIBE_TARGET_GROUPS_RESPONSE[
            'TargetGroups']
        get_target_group_healths_mock.return_value = {
            "arn:aws:elasticloadbalancing:us-west-2:123123123123:targetgroup/awseb-AWSEB-179V6JWWL9HI5/e57decc4139bfdd2":
            mock_responses.DESCRIBE_TARGET_HEALTH_RESPONSE
        }

        statusops.status('my-application', 'environment-1', True)

        log_alert_mock.assert_not_called()
        echo_mock.assert_has_calls([
            mock.call('Environment details for:', 'environment-1'),
            mock.call('  Application name:', 'my-application'),
            mock.call('  Region:', 'us-west-2'),
            mock.call('  Deployed Version:', 'Sample Application'),
            mock.call('  Environment ID:', 'e-sfsdfsfasdads'),
            mock.call(
                '  Platform:',
                PlatformVersion(
                    'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
                )),
            mock.call('  Tier:', Tier.from_raw_string('webserver')),
            mock.call('  CNAME:',
                      'environment-1.us-west-2.elasticbeanstalk.com'),
            mock.call(
                '  Updated:',
                datetime.datetime(2018,
                                  3,
                                  27,
                                  23,
                                  47,
                                  41,
                                  830000,
                                  tzinfo=tz.tzutc())),
            mock.call('  Status:', 'Ready'),
            mock.call('  Health:', 'Green'),
            mock.call('  Running instances:', 1),
            mock.call('          ', 'i-01641763db1c0cb47: healthy'),
            mock.call('Current CodeCommit settings:'),
            mock.call('  Repository: repository'),
            mock.call('  Branch: branch')
        ])
    def test_status__verbose_mode__elb(
            self, get_health_of_instances_mock, get_environment_resources_mock,
            get_default_repository_mock, get_default_branch_mock, echo_mock,
            log_alert_mock, find_solution_stack_from_string_mock,
            get_environment_mock):
        environment_object = Environment.json_to_environment_object(
            mock_responses.DESCRIBE_ENVIRONMENTS_RESPONSE['Environments'][0])
        environment_object.platform = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
        )
        get_environment_mock.return_value = environment_object
        find_solution_stack_from_string_mock.return_value = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
        )
        get_default_branch_mock.return_value = 'branch'
        get_default_repository_mock.return_value = 'repository'
        get_environment_resources_mock.return_value = mock_responses.DESCRIBE_ENVIRONMENT_RESOURCES_RESPONSE
        get_health_of_instances_mock.return_value = mock_responses.DESCRIBE_INSTANCE_HEALTH[
            'InstanceStates']

        statusops.status('my-application', 'environment-1', True)

        log_alert_mock.assert_not_called()
        echo_mock.assert_has_calls([
            mock.call('Environment details for:', 'environment-1'),
            mock.call('  Application name:', 'my-application'),
            mock.call('  Region:', 'us-west-2'),
            mock.call('  Deployed Version:', 'Sample Application'),
            mock.call('  Environment ID:', 'e-sfsdfsfasdads'),
            mock.call(
                '  Platform:',
                PlatformVersion(
                    'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
                )),
            mock.call('  Tier:', Tier.from_raw_string('webserver')),
            mock.call('  CNAME:',
                      'environment-1.us-west-2.elasticbeanstalk.com'),
            mock.call(
                '  Updated:',
                datetime.datetime(2018,
                                  3,
                                  27,
                                  23,
                                  47,
                                  41,
                                  830000,
                                  tzinfo=tz.tzutc())),
            mock.call('  Status:', 'Ready'),
            mock.call('  Health:', 'Green'),
            mock.call('  Running instances:', 2),
            mock.call('     ', 'i-23452345346456566:', 'InService'),
            mock.call('     ', 'i-21312312312312312:', 'OutOfService'),
            mock.call('Current CodeCommit settings:'),
            mock.call('  Repository: repository'),
            mock.call('  Branch: branch')
        ])
    def test_status__non_verbose_mode__codecommit_not_setup__using_non_latest_platform(
            self, get_default_repository_mock, get_default_branch_mock,
            echo_mock, log_alert_mock, find_solution_stack_from_string_mock,
            get_environment_mock):
        environment_object = Environment.json_to_environment_object(
            mock_responses.DESCRIBE_ENVIRONMENTS_RESPONSE['Environments'][0])
        environment_object.platform = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.5'
        )
        get_environment_mock.return_value = environment_object
        get_environment_mock.platform = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.5'
        )
        find_solution_stack_from_string_mock.return_value = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
        )
        get_default_branch_mock.return_value = None
        get_default_repository_mock.return_value = None

        statusops.status('my-application', 'environment-1', False)

        log_alert_mock.assert_called_once_with(
            'There is a newer version of the platform used by your environment. '
            'You can upgrade your environment to the most recent platform version by typing "eb upgrade".'
        )
        echo_mock.assert_has_calls([
            mock.call('Environment details for:', 'environment-1'),
            mock.call('  Application name:', 'my-application'),
            mock.call('  Region:', 'us-west-2'),
            mock.call('  Deployed Version:', 'Sample Application'),
            mock.call('  Environment ID:', 'e-sfsdfsfasdads'),
            mock.call(
                '  Platform:',
                PlatformVersion(
                    'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.5'
                )),
            mock.call('  Tier:', Tier.from_raw_string('webserver')),
            mock.call('  CNAME:',
                      'environment-1.us-west-2.elasticbeanstalk.com'),
            mock.call(
                '  Updated:',
                datetime.datetime(2018,
                                  3,
                                  27,
                                  23,
                                  47,
                                  41,
                                  830000,
                                  tzinfo=tz.tzutc())),
            mock.call('  Status:', 'Ready'),
            mock.call('  Health:', 'Green')
        ])
Ejemplo n.º 4
0
def get_environment_tier(tier):
    """
    Set the 'tier' for the environment from the raw value received for the `--tier`
    argument.

    If a configuration template corresponding to `template_name` is also resolved,
    and the tier corresponding to the configuration template is a 'worker' tier,
    any previously set value for 'tier' is replaced with the value from the saved
    config.
    :return: A Tier object representing the environment's tier type
    """
    if tier:
        tier = Tier.from_raw_string(tier)

    return tier
 def test_from_raw_string__invalid_input(self):
     with self.assertRaises(NotFoundError):
         Tier.from_raw_string('invalid/input')
 def test_from_raw_string__worker(self):
     for customer_input in ['Worker', 'Worker/SQS/HTTP']:
         tier = Tier.from_raw_string(customer_input)
         self.assertEqual('Worker', tier.name)
         self.assertEqual('SQS/HTTP', tier.type)
         self.assertEqual('', tier.version)
 def test_from_raw_string__webserver(self):
     for customer_input in ['WebServer', 'WebServer/Standard']:
         tier = Tier.from_raw_string(customer_input)
         self.assertEqual('WebServer', tier.name)
         self.assertEqual('Standard', tier.type)
         self.assertEqual('1.0', tier.version)