예제 #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_status(self):
     test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
     c = Config(
         project_config_path=test_proj / "ci" / "taskcat.yml",
         project_root=test_proj,
         create_clients=False,
     )
     stacker = Stacker(c)
     stacker.create_stacks()
     stacker.stacks[0].id = "stack-id"
     stacker.stacks[0].status_reason = ""
     stacker.stacks[0].status = "CREATE_COMPLETE"
     stacker.stacks[1].id = "stack-id2"
     stacker.stacks[1].status_reason = ""
     stacker.stacks[1].status = "CREATE_IN_PROGRESS"
     statuses = stacker.status()
     expected = {
         "COMPLETE": {
             "stack-id": ""
         },
         "FAILED": {},
         "IN_PROGRESS": {
             "stack-id2": ""
         },
     }
     self.assertEqual(expected, statuses)
예제 #3
0
 def test_init(self):
     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()
     template = templates["taskcat-json"]
     self.assertEqual(1, len(template.children))
     self.assertEqual(4, len(template.descendents))
예제 #4
0
 def test_from_existing(self, m_import):
     test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
     c = Config(
         project_config_path=test_proj / "ci" / "taskcat.yml",
         project_root=test_proj,
         create_clients=False,
     )
     s = Stacker.from_existing(uuid.UUID(int=0), c)
     self.assertEqual([], s.stacks)
예제 #5
0
    def setUpClass(cls):
        input_file = ".taskcat.yml"
        project_root_path = Path(__file__).parent / "../data/nested-fail"
        input_file_path = project_root_path / input_file

        cls.base_config = Config.create(
            project_root=project_root_path,
            project_config_path=input_file_path,
        )
예제 #6
0
 def test_create_stacks(self):
     test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
     c = Config(
         project_config_path=test_proj / "ci" / "taskcat.yml",
         project_root=test_proj,
         create_clients=False,
     )
     stacker = Stacker(c)
     stacker.create_stacks()
     self.assertEqual(2, len(stacker.stacks))
예제 #7
0
 def test_delete_stacks(self):
     test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
     c = Config(
         project_config_path=test_proj / "ci" / "taskcat.yml",
         project_root=test_proj,
         create_clients=False,
     )
     stacker = Stacker(c)
     stacker.create_stacks()
     stacker.delete_stacks()
     stacker.stacks[0].delete.assert_called_once()
예제 #8
0
 def test_do_validate(self):
     test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
     c = Config(
         project_config_path=test_proj / "ci" / "taskcat.yml",
         project_root=test_proj,
         create_clients=False,
     )
     template = c.tests["taskcat-json"].template
     template.client_factory_instance = mock.Mock()
     template._do_validate("some-url", "some-region")
     template.client_factory_instance.get.assert_called_once()
예제 #9
0
 def test_delete_s3_object(self):
     test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
     c = Config(
         project_config_path=test_proj / "ci" / "taskcat.yml",
         project_root=test_proj,
         create_clients=False,
     )
     template = c.tests["taskcat-json"].template
     template.client_factory_instance = mock.Mock()
     template._delete_s3_object("s3://bucket_name/prefix/file")
     template.client_factory_instance.get.assert_called_once()
예제 #10
0
def get_config():
    project_root_path = Path(__file__).parent / "../data/hook_plugin"
    input_file_path = project_root_path / ".taskcat.yml"
    config = Config.create(
        project_root=project_root_path,
        project_config_path=input_file_path,
    )
    config.get_buckets = MagicMock()
    config.get_regions = MagicMock()
    config.get_rendered_parameters = MagicMock()
    config.get_tests = MagicMock()
    return config
예제 #11
0
 def test_upload(self, m_s3_url_maker):
     test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
     c = Config(
         project_config_path=test_proj / "ci" / "taskcat.yml",
         project_root=test_proj,
         create_clients=False,
     )
     template = c.tests["taskcat-json"].template
     template.client_factory_instance = mock.Mock()
     resp = template._upload("my-bucket", "my-prefix")
     self.assertEqual(resp, "test-url")
     template.client_factory_instance.get.assert_called_once()
     m_s3_url_maker.assert_called_once()
예제 #12
0
 def test_validate(self, m_delete, m_do_val, m_create):
     test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
     c = Config(
         project_config_path=test_proj / "ci" / "taskcat.yml",
         project_root=test_proj,
         create_clients=False,
     )
     template = c.tests["taskcat-json"].template
     with self.assertRaises(ValueError) as _:
         resp = template.validate("us-east-1")
     resp = template.validate("us-east-1", "my-bucket")
     self.assertEqual(None, resp)
     m_delete.assert_called_once()
     m_do_val.assert_called_once()
     m_create.assert_called_once()
예제 #13
0
 def test_create_temp_s3_object(self, m_upload):
     test_proj = (Path(__file__).parent / "./data/nested-fail").resolve()
     c = Config(
         project_config_path=test_proj / "ci" / "taskcat.yml",
         project_root=test_proj,
         create_clients=False,
     )
     template = c.tests["taskcat-json"].template
     resp = template._create_temporary_s3_object("test_bucket",
                                                 "test_prefix")
     self.assertEqual(resp, "test-resp")
     template.url = "a-url"
     resp = template._create_temporary_s3_object("test_bucket",
                                                 "test_prefix")
     self.assertEqual(resp, "")
예제 #14
0
def get_tests(test_proj, _):
    c = Config.create(
        project_config_path=test_proj / ".taskcat.yml", project_root=test_proj
    )
    boto_cache = get_mock_boto_cache()
    templates = c.get_templates()
    regions = c.get_regions(boto3_cache=boto_cache)
    buckets = c.get_buckets(boto_cache)
    params = c.get_rendered_parameters(buckets, regions, templates)
    return (
        c.config.project.name,
        c.get_tests(
            templates=templates, regions=regions, buckets=buckets, parameters=params,
        ),
    )