Пример #1
0
 def test_wait_for_in_service_health_failure(self):
     asg_name = "unhealthy_asg"
     create_asg_with_tags(asg_name, {"foo": "bar"})
     autoscale = boto.connect_autoscale()
     asgs = autoscale.get_all_groups([asg_name])
     asg = asgs[0]
     asg.instances[0].health_status = "Unhealthy"
     with mock.patch("boto.ec2.autoscale.AutoScaleConnection.get_all_groups", return_value=asgs):
         self.assertRaises(TimeoutException, ec2.wait_for_in_service, [asg_name], 2)
Пример #2
0
    def test_get_asgs_pending_delete(self):
        asg_name = "test-asg-deletion"
        deletion_dttm_str = datetime.datetime.utcnow().isoformat()
        create_asg_with_tags(asg_name, {ec2.ASG_DELETE_TAG_KEY: deletion_dttm_str})

        asgs = ec2.get_asgs_pending_delete()
        self.assertEqual(len(asgs), 1)
        asg = asgs.pop()
        self.assertEqual(asg.name, asg_name)
        self.assertEqual(asg.tags[0].key, ec2.ASG_DELETE_TAG_KEY)
        self.assertEqual(asg.tags[0].value, deletion_dttm_str)
Пример #3
0
    def test_get_asgs_pending_delete(self):
        asg_name = "test-asg-deletion"
        deletion_dttm_str = datetime.datetime.utcnow().isoformat()
        create_asg_with_tags(asg_name,
                             {ec2.ASG_DELETE_TAG_KEY: deletion_dttm_str})

        asgs = ec2.get_asgs_pending_delete()
        self.assertEqual(len(asgs), 1)
        asg = asgs.pop()
        self.assertEqual(asg.name, asg_name)
        self.assertEqual(asg.tags[0].key, ec2.ASG_DELETE_TAG_KEY)
        self.assertEqual(asg.tags[0].value, deletion_dttm_str)
Пример #4
0
 def test_wait_for_in_service_health_failure(self):
     asg_name = "unhealthy_asg"
     create_asg_with_tags(asg_name, {"foo": "bar"})
     autoscale = boto.connect_autoscale()
     asgs = autoscale.get_all_groups([asg_name])
     asg = asgs[0]
     asg.instances[0].health_status = "Unhealthy"
     with mock.patch(
             "boto.ec2.autoscale.AutoScaleConnection.get_all_groups",
             return_value=asgs):
         self.assertRaises(TimeoutException, ec2.wait_for_in_service,
                           [asg_name], 2)
Пример #5
0
    def test_get_all_autoscale_groups(self, asg_count, expected_result_count, name_filter):
        """
        While I have attempted to test for pagination the moto library does not seem to support this and returns
        all of the ASGs created on the first get request and not 50 per request.
        """
        for i in range(asg_count):
            create_asg_with_tags("asg_{}".format(i), {"environment": "foo", "deployment": "bar", "play": "baz"})
        asgs = ec2.get_all_autoscale_groups(name_filter)

        self.assertIsInstance(asgs, list)
        self.assertEquals(len(asgs), expected_result_count)
        if name_filter:
            self.assertTrue(all(asg.name in name_filter for asg in asgs))
Пример #6
0
    def test_asgs_for_edp(self, params):
        asgs, expected_returned_count, expected_asg_names_list = params

        edp = EDP("foo", "bar", "baz")

        for name, tags in asgs.viewitems():
            create_asg_with_tags(name, tags)

        asgs = ec2.asgs_for_edp(edp)
        self.assertIsInstance(asgs, list)

        self.assertEquals(len(asgs), expected_returned_count)
        self.assertTrue(all(asg_name in asgs for asg_name in expected_asg_names_list))
Пример #7
0
    def test_asgs_for_edp(self, params):
        asgs, expected_returned_count, expected_asg_names_list = params

        edp = EDP("foo", "bar", "baz")

        for name, tags in six.viewitems(asgs):
            create_asg_with_tags(name, tags)

        asgs = ec2.asgs_for_edp(edp)
        self.assertIsInstance(asgs, list)

        self.assertEqual(len(asgs), expected_returned_count)
        self.assertTrue(
            all(asg_name in asgs for asg_name in expected_asg_names_list))
Пример #8
0
    def test_get_asgs_pending_delete_incorrectly_formatted_timestamp(self):
        asg_name1 = "test-asg-deletion"
        asg_name2 = "test-asg-deletion-bad-timestamp"
        deletion_dttm_str1 = datetime.datetime.utcnow().isoformat()
        deletion_dttm_str2 = "2016-05-18 18:19:46.144884"
        create_asg_with_tags(asg_name1, {ec2.ASG_DELETE_TAG_KEY: deletion_dttm_str1})
        create_asg_with_tags(asg_name2, {ec2.ASG_DELETE_TAG_KEY: deletion_dttm_str2})

        asgs = ec2.get_asgs_pending_delete()
        self.assertEqual(len(asgs), 1)
        # boto.ec2.autoscale.group.AutoScalingGroup does not implement __eq__ so we need to iterate the list to see if
        # the ASGs we are interested in are members
        self.assertEqual(len([asg for asg in asgs if asg.name == asg_name1]), 1)
        self.assertEqual(len([asg for asg in asgs if asg.name == asg_name2]), 0)
Пример #9
0
 def test_ami_for_edp_success(self):
     fake_ami_id = self._make_fake_ami()
     fake_elb_name = "healthy-lb-1"
     fake_elb = create_elb(fake_elb_name)
     fake_asg_name = "fully_tagged_asg"
     fake_asg_tags = {
         "environment": "foo",
         "deployment": "bar",
         "play": "baz"
     }
     create_asg_with_tags(fake_asg_name,
                          fake_asg_tags,
                          ami_id=fake_ami_id,
                          elbs=[fake_elb])
     self.assertEqual(ec2.active_ami_for_edp('foo', 'bar', 'baz'),
                      fake_ami_id)
Пример #10
0
    def test_get_asgs_pending_delete_incorrectly_formatted_timestamp(self):
        asg_name1 = "test-asg-deletion"
        asg_name2 = "test-asg-deletion-bad-timestamp"
        deletion_dttm_str1 = datetime.datetime.utcnow().isoformat()
        deletion_dttm_str2 = "2016-05-18 18:19:46.144884"
        create_asg_with_tags(asg_name1,
                             {ec2.ASG_DELETE_TAG_KEY: deletion_dttm_str1})
        create_asg_with_tags(asg_name2,
                             {ec2.ASG_DELETE_TAG_KEY: deletion_dttm_str2})

        asgs = ec2.get_asgs_pending_delete()
        self.assertEqual(len(asgs), 1)
        # boto.ec2.autoscale.group.AutoScalingGroup does not implement __eq__ so we need to iterate the list to see if
        # the ASGs we are interested in are members
        self.assertEqual(len([asg for asg in asgs if asg.name == asg_name1]),
                         1)
        self.assertEqual(len([asg for asg in asgs if asg.name == asg_name2]),
                         0)
Пример #11
0
    def test_get_all_autoscale_groups(self, asg_count, expected_result_count,
                                      name_filter):
        """
        While I have attempted to test for pagination the moto library does not seem to support this and returns
        all of the ASGs created on the first get request and not 50 per request.
        """
        for i in range(asg_count):
            create_asg_with_tags("asg_{}".format(i), {
                "environment": "foo",
                "deployment": "bar",
                "play": "baz"
            })
        asgs = ec2.get_all_autoscale_groups(name_filter)

        self.assertIsInstance(asgs, list)
        self.assertEqual(len(asgs), expected_result_count)
        if name_filter:
            self.assertTrue(all(asg.name in name_filter for asg in asgs))
Пример #12
0
 def test_ami_for_edp_multiple_amis(self):
     fake_ami_id1 = self._make_fake_ami()
     fake_ami_id2 = self._make_fake_ami()
     fake_elb_name = "healthy-lb-1"
     fake_elb = create_elb(fake_elb_name)
     fake_asg_name1 = "fully_tagged_asg1"
     fake_asg_name2 = "fully_tagged_asg2"
     fake_asg_tags = {
         "environment": "foo",
         "deployment": "bar",
         "play": "baz"
     }
     create_asg_with_tags(fake_asg_name1,
                          fake_asg_tags,
                          ami_id=fake_ami_id1,
                          elbs=[fake_elb])
     create_asg_with_tags(fake_asg_name2,
                          fake_asg_tags,
                          ami_id=fake_ami_id2,
                          elbs=[fake_elb])
     with self.assertRaises(MultipleImagesFoundException):
         ec2.active_ami_for_edp('foo', 'bar', 'baz')
Пример #13
0
 def test_wait_for_in_service(self):
     create_asg_with_tags("healthy_asg", {"foo": "bar"})
     self.assertEqual(None, ec2.wait_for_in_service(["healthy_asg"], 2))
Пример #14
0
 def test_wait_for_in_service(self):
     create_asg_with_tags("healthy_asg", {"foo": "bar"})
     self.assertEqual(None, ec2.wait_for_in_service(["healthy_asg"], 2))