예제 #1
0
    def test_descentants(self, m_evnts, __):
        region = make_test_region_obj("us-west-2")
        region.client = mock_client_method
        test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
        c = Config.create(project_config_path=test_proj / ".taskcat.yml",
                          project_root=test_proj)
        templates = c.get_templates()
        stack = Stack.create(region, "stack_name", templates["taskcat-json"])
        stack._timer.cancel()

        child = event_template.copy()
        grandchild = event_template.copy()
        child["PhysicalResourceId"] = (
            "arn:aws:cloudformation:us-east-1:123456789012:"
            "stack/Child/e722ae60-fe62-11e8-9a0e-0ae8cc519969")
        child["ResourceProperties"] = (
            '{"TemplateURL": "https://test.s3.amazonaws.com/templates/'
            'test.template_inner.yaml"}')
        grandchild["PhysicalResourceId"] = (
            "arn:aws:cloudformation:us-east-1:123456789012:stack/GrandChild/"
            "e722ae60-fe62-11e8-9a0e-0ae8cc519970")
        grandchild["ResourceProperties"] = (
            '{"TemplateURL": "https://test.s3.amazonaws.com/templates/'
            'test.template_middle.yaml"}')
        m_evnts.return_value = Events([Event(child), Event(grandchild)])

        desc = stack.descendants()
        self.assertEqual(len(desc), 2)
예제 #2
0
    def test_events(self, mock_template, m_eve, _):
        region = make_test_region_obj("us-west-2")
        m_template = make_test_template()
        stack = Stack.create(region, "stack_name", m_template)
        stack._timer.cancel()
        generic_evnt = event_template.copy()
        not_generic_evnt = event_template.copy()
        generic_evnt["ResourceStatusReason"] = "Resource creation cancelled"
        generic_evnt["LogicalResourceId"] = "generic"
        not_generic_evnt["LogicalResourceId"] = "not-generic"
        stack._events = Events([Event(generic_evnt), Event(not_generic_evnt)])

        actual = stack.events()
        m_eve.assert_called_once()
        self.assertEqual(len(actual), 2)

        stack._last_event_refresh = datetime.now()
        actual = stack.events(include_generic=False)
        m_eve.assert_called_once()
        self.assertEqual(len(actual), 1)
예제 #3
0
    def test_event(self):
        event_dict = event_template.copy()
        event = Event(event_dict)
        self.assertEqual(event.physical_id, "")
        self.assertEqual(event.properties, {})
        self.assertEqual(event.status_reason, "")
        self.assertEqual(event.timestamp, datetime.fromtimestamp(0))
        event_dict["PhysicalResourceId"] = "test_id"
        now = datetime.now()
        event_dict["Timestamp"] = now
        event_dict["ResourceStatusReason"] = "test_reason"
        event_dict["ResourceProperties"] = '{"test_prop_key": "test_value"}'
        event = Event(event_dict)
        self.assertEqual(event.physical_id, "test_id")
        self.assertEqual(event.properties, {"test_prop_key": "test_value"})
        self.assertEqual(event.status_reason, "test_reason")
        self.assertEqual(event.timestamp, now)

        expected = "{} {} {}".format(now, "test_logical_id", "CREATE_IN_PROGRESS")
        self.assertEqual(expected, str(event))
        expected = "<Event object {} at {}>".format("test_event_id", hex(id(event)))
        self.assertEqual(expected, event.__repr__())
예제 #4
0
    def test_events(self, m_eve, _):
        m_cf = mock.Mock()
        region = AWSRegionObject("us-west-2", m_cf)
        region.s3bucket = mock.Mock()
        region.client = mock_client_method
        m_template = mock.Mock()
        stack = Stack.create(region, "stack_name", m_template)
        stack._timer.cancel()
        generic_evnt = event_template.copy()
        not_generic_evnt = event_template.copy()
        generic_evnt["ResourceStatusReason"] = "Resource creation cancelled"
        generic_evnt["LogicalResourceId"] = "generic"
        not_generic_evnt["LogicalResourceId"] = "not-generic"
        stack._events = Events([Event(generic_evnt), Event(not_generic_evnt)])

        actual = stack.events()
        m_eve.assert_called_once()
        self.assertEqual(len(actual), 2)

        stack._last_event_refresh = datetime.now()
        actual = stack.events(include_generic=False)
        m_eve.assert_called_once()
        self.assertEqual(len(actual), 1)