Exemplo n.º 1
0
    def test_export_environment_variables(self):
        content = """
# comment
FIRST=one
# WRONG=another
SECOND=two
"""
        Configurator.export_environment_variables(content)
        self.assertEqual('one', os.environ.get('FIRST', None))
        self.assertEqual('two', os.environ.get('SECOND', None))
        self.assertIsNone(os.environ.get('WRONG', None))
Exemplo n.º 2
0
    def test_update_deck_settings(self):
        temp_sourcedir = tempfile.mkdtemp()
        temp_targetdir = tempfile.mkdtemp()
        template = """
preamble
// BEGIN reconfigure_spinnaker
// var gateUrl = ${{services.gate.baseUrl}};
{gate_url_value}
// var bakeryBaseUrl = ${{services.bakery.baseUrl}};
{bakery_url_value}
// END reconfigure_spinnaker
// var gateUrl = ${{services.gate.baseUrl}};
stuff here is left along.
"""
        # This was originally just a comment, which was preserved.
        bakery_url_assignment = ("var bakeryBaseUrl = 'BAKERY_BASE_URL';"
                                 "\n# comment")

        # This was originally a different let statement that was removed.
        gate_url_assignment = "var gateUrl = 'GATE_BASE_URL';"
        bindings = YamlBindings()
        bindings.import_dict({
            'services': {
                'gate': { 'baseUrl': 'GATE_BASE_URL' },
                'bakery': { 'baseUrl': 'BAKERY_BASE_URL' },
             }
        })

        installation = InstallationParameters
        installation.INSTALLED_CONFIG_DIR = temp_sourcedir
        installation.DECK_INSTALL_DIR = temp_targetdir
        configurator = Configurator(installation_parameters=installation,
                                    bindings=bindings)
        try:
            source_settings_path = os.path.join(temp_sourcedir, 'settings.js')
            target_settings_path = os.path.join(temp_targetdir, 'settings.js')
            with open(source_settings_path, 'w') as f:
                f.write(template.format(gate_url_value="var gateUrl='old';",
                                        bakery_url_value='# comment'))

            configurator.update_deck_settings()
            with open(target_settings_path, 'r') as f:
                got = f.read()
            expect = template.format(gate_url_value=gate_url_assignment,
                                     bakery_url_value=bakery_url_assignment)
            self.assertEqual(expect, got)
        finally:
            shutil.rmtree(temp_sourcedir)
            shutil.rmtree(temp_targetdir)
Exemplo n.º 3
0
 def test_true_false_bad(self):
     bindings = YamlBindings()
     bindings.import_dict({
         't': 'true',
         'f': 'false',
         'indirect': '${t}',
         'default': '${x:0}'
     })
     validator = ValidateConfig(configurator=Configurator(
         bindings=bindings))
     self.assertFalse(validator.verify_true_false('t'))
     self.assertFalse(validator.verify_true_false('f'))
     self.assertFalse(validator.verify_true_false('indirect'))
     self.assertFalse(validator.verify_true_false('default'))
     self.assertEqual(4, len(validator.errors))
     self.assertEqual(0, len(validator.warnings))
     self.assertEqual([
         "t='true' is not valid. Must be boolean true or false.",
         "f='false' is not valid. Must be boolean true or false.",
         "indirect='true' is not valid. Must be boolean true or false.",
         "default=0 is not valid. Must be boolean true or false."
     ], validator.errors)
Exemplo n.º 4
0
 def test_verify_at_least_one_provider_enabled_bad(self):
     bindings = YamlBindings()
     bindings.import_dict({
         'providers': {
             'aws': {
                 'enabled': False
             },
             'google': {
                 'enabled': False
             }
         },
         'services': {
             'test': {
                 'enabled': True
             }
         }
     })
     validator = ValidateConfig(configurator=Configurator(
         bindings=bindings))
     self.assertFalse(validator.verify_at_least_one_provider_enabled())
     self.assertEqual('None of the providers are enabled.',
                      validator.errors[0])
Exemplo n.º 5
0
    def test_configuration(self):
        temp_homedir = tempfile.mkdtemp()
        home_spinnaker_dir = os.path.join(temp_homedir, '.spinnaker')
        os.mkdir(home_spinnaker_dir)
        with open(os.path.join(home_spinnaker_dir, 'spinnaker-local.yml'),
                  'w') as f:
            f.write('empty:\n')

        # We aren't using HOME in a test, but want to verify that it is
        # being used.
        old_home = os.environ['HOME']
        os.environ['HOME'] = temp_homedir
        try:
            configurator = Configurator()
        finally:
            os.environ['HOME'] = old_home

        self.assertEquals(home_spinnaker_dir, configurator.user_config_dir)
        self.assertEquals(
            os.path.abspath(
                os.path.join(os.path.dirname(sys.argv[0]), '../config')),
            configurator.installation_config_dir)
Exemplo n.º 6
0
 def test_is_reference_good(self):
     bindings = YamlBindings()
     validator = ValidateConfig(configurator=Configurator(
         bindings=bindings))
     self.assertTrue(validator.is_reference('${a}'))
     self.assertTrue(validator.is_reference('${a:value'))