Exemplo n.º 1
0
    def test_handling_sources_with_multiple_hashes_and_cache_url(
            self, mock_fetch_file, mock_check_sum):
        with self.descriptor as f:
            f.write(
                "sources:\n  - artifact: http://somehost.com/file.zip\n    md5: e9013fc202c87be48e3b302df10efc4b\n    sha1: 105bfe02a86ba69be5506cd559a54c4b252fb132"
                .encode())

        k = mock.patch.dict(
            os.environ,
            {'DOGEN_SOURCES_CACHE': 'http://cache/get?#algorithm#=#hash#'})
        k.start()
        generator = Generator(self.log, self.args)
        generator.configure()
        generator.handle_sources()
        k.stop()

        mock_fetch_file.assert_called_with(
            'http://cache/get?sha1=105bfe02a86ba69be5506cd559a54c4b252fb132',
            'target/file.zip')
        calls = [
            mock.call('target/file.zip',
                      '105bfe02a86ba69be5506cd559a54c4b252fb132', 'sha1'),
            mock.call('target/file.zip', 'e9013fc202c87be48e3b302df10efc4b',
                      'md5')
        ]
        mock_check_sum.assert_has_calls(calls)
    def test_skip_ssl_verification_in_descriptor(self):
        with self.descriptor as f:
            f.write("dogen:\n  ssl_verify: false".encode())

        generator = Generator(self.log, self.descriptor.name, "target")
        generator.configure()
        self.assertFalse(generator.ssl_verify)
Exemplo n.º 3
0
    def test_do_not_skip_ssl_verification_in_descriptor(self):
        with self.descriptor as f:
            f.write("dogen:\n  ssl_verify: true".encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        self.assertTrue(generator.ssl_verify)
Exemplo n.º 4
0
    def test_custom_template_in_descriptor(self):
        with self.descriptor as f:
            f.write("dogen:\n  template: custom-template.jinja".encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        self.assertEqual(generator.template, "custom-template.jinja")
Exemplo n.º 5
0
 def test_custom_template_in_cli_should_override_in_descriptor(self):
     with self.descriptor as f:
         f.write("dogen:\n  template: custom-template.jinja".encode())
     args = self.args
     args.template = "cli-template.jinja"
     generator = Generator(self.log, args)
     generator.configure()
     self.assertEqual(generator.template, "cli-template.jinja")
    def test_custom_scripts_dir_in_descriptor(self, mock_patch):
        with self.descriptor as f:
            f.write("dogen:\n  scripts: custom-scripts".encode())

        generator = Generator(self.log, self.descriptor.name, "target")
        generator.configure()
        mock_patch.assert_called_with('custom-scripts')
        self.assertEqual(generator.scripts, "custom-scripts")
Exemplo n.º 7
0
    def test_scripts_dir_found_by_convention(self, mock_patch):
        with self.descriptor as f:
            f.write("dogen:\n  scripts_path: custom-scripts".encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        mock_patch.assert_called_with('custom-scripts')
        self.assertEqual(generator.scripts_path, "custom-scripts")
Exemplo n.º 8
0
 def test_do_not_skip_ssl_verification_in_cli_false_should_override_descriptor(
         self):
     with self.descriptor as f:
         f.write("dogen:\n  ssl_verify: true".encode())
     args = self.args
     args.skip_ssl_verification = True
     generator = Generator(self.log, args)
     generator.configure()
     self.assertFalse(generator.ssl_verify)
Exemplo n.º 9
0
    def test_do_not_fail_if_no_template_is_provided(self):
        self.generator = Generator(self.log, "image.yaml", "target")
        fetch_file_mock = mock.Mock()
        self.generator._fetch_file = fetch_file_mock

        self.assertEqual(self.generator.template, None)
        self.generator._handle_custom_template()
        fetch_file_mock.assert_not_called()
        self.assertEqual(self.generator.template, None)
Exemplo n.º 10
0
    def test_no_scripts_defined(self):
        "make sure _handle_scripts doesn't blow up when there are no scripts"

        self.descriptor.close()
        args = self.args
        args.scripts_path = "scripts"
        generator = Generator(self.log, args)
        generator.configure()
        generator._handle_scripts()
Exemplo n.º 11
0
    def setUp(self):
        self.log = mock.Mock()
        self.descriptor = tempfile.NamedTemporaryFile(delete=False)

        with self.descriptor as f:
            f.write("dogen:\n  ssl_verify: true".encode())

        self.generator = Generator(self.log, self.descriptor.name, "target")
        self.generator.configure()
Exemplo n.º 12
0
 def helper_test_script_exec(self, exec_to_test, cfg, mock_patch):
     """Helper method for tests around script exec value"""
     with self.descriptor as f:
         f.write(cfg.encode())
     args = self.args
     args.scripts_path = "scripts"
     generator = Generator(self.log, args)
     generator.configure()
     generator._handle_scripts()
     self.assertEqual(generator.cfg['scripts'][0]['exec'], exec_to_test)
Exemplo n.º 13
0
 def test(self):
     args = argparse.Namespace(path=path, output="target", without_sources=None,
                               template=None, scripts_path=None, additional_script=None,
                               skip_ssl_verification=None)
     generator = Generator(self.log, args)
     if good:
         generator.configure()
     else:
         with self.assertRaises(Error):
             generator.configure()
Exemplo n.º 14
0
 def test_custom_scripts_dir_in_cli_should_override_in_descriptor(
         self, mock_patch):
     with self.descriptor as f:
         f.write("dogen:\n  template: custom-scripts".encode())
     args = self.args
     args.scripts_path = "custom-scripts-cli"
     generator = Generator(self.log, args)
     generator.configure()
     mock_patch.assert_called_with('custom-scripts-cli')
     self.assertEqual(generator.scripts_path, "custom-scripts-cli")
Exemplo n.º 15
0
 def prepare_dogen(self, repo_files_dir=None):
     args = argparse.Namespace(path=self.descriptor.name,
                               output=self.target_dir,
                               without_sources=None,
                               template=None,
                               scripts_path=None,
                               additional_script=None,
                               skip_ssl_verification=None,
                               repo_files_dir=repo_files_dir)
     self.dogen = Generator(self.log, args, [Repo])
Exemplo n.º 16
0
 def test_default_values(self):
     self.generator = Generator(self.log, self.args)
     self.assertEqual(self.generator.output, "target")
     self.assertEqual(self.generator.dockerfile, "target/Dockerfile")
     self.assertEqual(self.generator.descriptor, self.descriptor.name)
     self.assertEqual(self.generator.template, None)
     self.assertEqual(self.generator.scripts_path, None)
     self.assertEqual(self.generator.without_sources, False)
     # Set to True in the configure() method later
     self.assertEqual(self.generator.ssl_verify, None)
    def test_custom_additional_scripts_in_descriptor(self):
        with self.descriptor as f:
            f.write(
                "dogen:\n  additional_scripts:\n    - http://host/somescript".
                encode())

        generator = Generator(self.log, self.descriptor.name, "target")
        generator.configure()
        self.assertEqual(generator.additional_scripts,
                         ["http://host/somescript"])
Exemplo n.º 18
0
    def helper_test_script_user(self, cfg, user_to_test, mock_patch):
        """A helper for script user-related tests"""

        with self.descriptor as f:
            f.write(cfg.encode())
        args = self.args
        args.scripts_path = "scripts"
        generator = Generator(self.log, args)
        generator.configure()
        generator._handle_scripts()
        self.assertEqual(generator.cfg['scripts'][0]['user'], user_to_test)
    def test_do_not_skip_ssl_verification_in_cli_false_should_override_descriptor(
            self):
        with self.descriptor as f:
            f.write("dogen:\n  ssl_verify: true".encode())

        generator = Generator(self.log,
                              self.descriptor.name,
                              "target",
                              ssl_verify=False)
        generator.configure()
        self.assertFalse(generator.ssl_verify)
Exemplo n.º 20
0
    def test_handling_sources_without_specified_md5sum(self, mock_fetch_file):
        with self.descriptor as f:
            f.write("sources:\n  - artifact: http://somehost.com/file.zip".
                    encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        generator.handle_sources()

        mock_fetch_file.assert_called_with('http://somehost.com/file.zip',
                                           'target/file.zip')
Exemplo n.º 21
0
    def test_handling_sources_when_local_file_exists_and_is_correct(
            self, mock_fetch_file, mock_check_sum, mock_path):
        with self.descriptor as f:
            f.write(
                "sources:\n  - artifact: http://somehost.com/file.zip\n    md5: e9013fc202c87be48e3b302df10efc4b"
                .encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        generator.handle_sources()

        self.assertEqual(mock_fetch_file.call_count, 0)
Exemplo n.º 22
0
    def test_generating_env_variables(self):
        with open(self.yaml, 'ab') as f:
            f.write("envs:\n  - name: INFO_ENV\n    value: 0\n  - name: CONFIG_ENV\n    example: 1234\n  - name: COMBINED_ENV\n    value: set_value\n    example: example_value\n    description: This is a description".encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        generator.render_from_template()

        with open(os.path.join(self.target, "Dockerfile"), "r") as f:
            dockerfile = f.read()
            regex = re.compile(r'ENV JBOSS_IMAGE_NAME=\"someimage\" \\\s+JBOSS_IMAGE_VERSION=\"1\" \\\s+INFO_ENV=\"0\" \\\s+COMBINED_ENV=\"set_value\" \n',  re.MULTILINE)
            self.assertRegexpMatches(dockerfile, regex)
    def test_no_scripts_defined(self):
        "make sure _handle_scripts doesn't blow up when there are no scripts"

        with self.descriptor as f:
            f.write("name: somecfg\n".encode())

        generator = Generator(self.log,
                              self.descriptor.name,
                              "target",
                              scripts="scripts")
        generator.configure()
        generator._handle_scripts()
    def test_do_not_fail_if_no_template_is_provided(self):
        args = argparse.Namespace(path="image.yaml", output="target", without_sources=None,
                                  template=None, scripts_path=None, additional_script=None,
                                  skip_ssl_verification=None)
        self.generator = Generator(self.log, args)

        fetch_file_mock = mock.Mock()
        self.generator._fetch_file = fetch_file_mock

        self.assertEqual(self.generator.template, None)
        self.generator._handle_custom_template()
        fetch_file_mock.assert_not_called()
        self.assertEqual(self.generator.template, None)
Exemplo n.º 25
0
    def test_handling_sources_with_target_filename(self, mock_fetch_file,
                                                   mock_check_sum):
        with self.descriptor as f:
            f.write(
                "sources:\n  - artifact: http://somehost.com/file.zip\n    md5: e9013fc202c87be48e3b302df10efc4b\n    target: target.zip"
                .encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        generator.handle_sources()

        mock_fetch_file.assert_called_with('http://somehost.com/file.zip',
                                           'target/target.zip')
Exemplo n.º 26
0
    def test_fail_if_version_mismatch(self):
        with self.descriptor as f:
            f.write("dogen:\n  version: 99999.9.9-dev1".encode())

        self.generator = Generator(self.log, self.args)

        with self.assertRaises(Error) as cm:
            self.generator.configure()

        self.assertEquals(
            str(cm.exception),
            "You try to parse descriptor that requires Dogen version 99999.9.9-dev1, but you run version %s"
            % version)
Exemplo n.º 27
0
    def test_debug_port(self):
        with open(self.yaml, 'ab') as f:
            f.write("ports:\n  - value: 8080\n  - value: 9999\n    expose: False".encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        generator.render_from_template()

        self.assertEqual(generator.cfg['ports'], [{'value': 8080}, {'expose': False, 'value': 9999}])

        with open(os.path.join(self.target, "Dockerfile"), "r") as f:
            dockerfile = f.read()
            regex = re.compile(r'.*EXPOSE 8080$',  re.MULTILINE)
            self.assertRegexpMatches(dockerfile, regex)
Exemplo n.º 28
0
    def test_generating_maintainer_label(self):
        with open(self.yaml, 'ab') as f:
            f.write("maintainer: Marek Goldmann".encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        generator.render_from_template()

        self.assertEqual(generator.cfg['labels'], [{'name': 'maintainer', 'value': 'Marek Goldmann'}])

        with open(os.path.join(self.target, "Dockerfile"), "r") as f:
            dockerfile = f.read()
            regex = re.compile(r'LABEL name=\"\$JBOSS_IMAGE_NAME\" \\\s+version=\"\$JBOSS_IMAGE_VERSION\" \\\s+architecture=\"x86_64\" \\\s+com.redhat.component=\"someimage\" \\\s+maintainer=\"Marek Goldmann\"',  re.MULTILINE)
            self.assertRegexpMatches(dockerfile, regex)
Exemplo n.º 29
0
    def test_generating_description_label(self):
        with open(self.yaml, 'ab') as f:
            f.write("description: This is a nice image".encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        generator.render_from_template()

        self.assertEqual(generator.cfg['labels'], [{'name': 'description', 'value': 'This is a nice image'}, {'name': 'summary', 'value': 'This is a nice image'}])

        with open(os.path.join(self.target, "Dockerfile"), "r") as f:
            dockerfile = f.read()
            regex = re.compile(r'LABEL name=\"\$JBOSS_IMAGE_NAME\" \\\s+version=\"\$JBOSS_IMAGE_VERSION\" \\\s+architecture=\"x86_64\" \\\s+com.redhat.component=\"someimage\" \\\s+description=\"This is a nice image\"',  re.MULTILINE)
            self.assertRegexpMatches(dockerfile, regex)
Exemplo n.º 30
0
    def test_handling_sources_with_sha1(self, mock_fetch_file, mock_check_sum):
        with self.descriptor as f:
            f.write(
                "sources:\n  - artifact: http://somehost.com/file.zip\n    sha1: 105bfe02a86ba69be5506cd559a54c4b252fb132"
                .encode())

        generator = Generator(self.log, self.args)
        generator.configure()
        generator.handle_sources()

        mock_fetch_file.assert_called_with('http://somehost.com/file.zip',
                                           'target/file.zip')
        mock_check_sum.assert_called_with(
            'target/file.zip', '105bfe02a86ba69be5506cd559a54c4b252fb132',
            'sha1')