def test_wait_for_autoscaling_using_amiid(self, mock_config, **kwargs): '''test wait for autoscaling using the ami id to identify the instances''' aws = DiscoAWS(config=mock_config, environment_name=TEST_ENV_NAME) instances = [{"InstanceId": "i-123123aa"}] aws.instances_from_amis = MagicMock(return_value=instances) aws.wait_for_autoscaling('ami-12345678', 1) aws.instances_from_amis.assert_called_with(['ami-12345678'], group_name=None, launch_time=None)
def test_instances_from_amis(self, mock_config, **kwargs): '''test get instances using ami ids ''' aws = DiscoAWS(config=mock_config, environment_name=TEST_ENV_NAME) instance = create_autospec(boto.ec2.instance.Instance) instance.id = "i-123123aa" instances = [instance] aws.instances = MagicMock(return_value=instances) self.assertEqual(aws.instances_from_amis('ami-12345678'), instances) aws.instances.assert_called_with(filters={"image_id": 'ami-12345678'}, instance_ids=None)
def test_instances_from_amis_with_group_name(self, mock_config, **kwargs): '''test get instances using ami ids in a specified group name''' aws = DiscoAWS(config=mock_config, environment_name=TEST_ENV_NAME) instance = create_autospec(boto.ec2.instance.Instance) instance.id = "i-123123aa" instances = [instance] aws.instances_from_asgs = MagicMock(return_value=instances) aws.instances = MagicMock(return_value=instances) self.assertEqual(aws.instances_from_amis('ami-12345678', group_name='test_group'), instances) aws.instances_from_asgs.assert_called_with(['test_group'])
def test_instances_from_amis_with_launch_date(self, mock_config, **kwargs): '''test get instances using ami ids and with date after a specified date time''' aws = DiscoAWS(config=mock_config, environment_name=TEST_ENV_NAME) now = datetime.utcnow() instance1 = create_autospec(boto.ec2.instance.Instance) instance1.id = "i-123123aa" instance1.launch_time = str(now + timedelta(minutes=10)) instance2 = create_autospec(boto.ec2.instance.Instance) instance2.id = "i-123123ff" instance2.launch_time = str(now - timedelta(days=1)) instances = [instance1, instance2] aws.instances = MagicMock(return_value=instances) self.assertEqual(aws.instances_from_amis('ami-12345678', launch_time=now), [instance1]) aws.instances.assert_called_with(filters={"image_id": 'ami-12345678'}, instance_ids=None)