def test_can_create_deployment_host_config_for_test2_host(self):
        """fab.tests.config.rsr.ci_deployment_host_config_test  Can create CI deployment host config for test2 host"""

        expected_test2_host_config = DeploymentHostConfig.create_with(
            HostAlias.TEST2, RepositoryBranch.DEVELOP, 'test2_rsrdb_develop')

        self.assertEqual(expected_test2_host_config,
                         CIDeploymentHostConfig.for_test2())
    def test_can_parse_preconfigured_test2_host_config_from_given_task_parameters(
            self):
        """fab.tests.config.loader.deployment_config_loader_test  Can parse preconfigured test2 host configuration from given task parameters"""

        self.mox.ReplayAll()

        self.assertEqual(
            CIDeploymentHostConfig.for_test2(),
            self.config_loader.parse(
                self._preconfigured_config_spec_for(HostAlias.TEST2)))
Пример #3
0
class DeploymentConfigLoader(object):

    preconfigured_hosts = { HostAlias.TEST:     CIDeploymentHostConfig.for_test(),
                            HostAlias.TEST2:    CIDeploymentHostConfig.for_test2(),
                            HostAlias.DATA:     DataHostConfig() }

    def __init__(self, feedback=ExecutionFeedback()):
        self.feedback = feedback

    def parse(self, config_specification):
        if self._invalid_host_config_format(config_specification):
            self.feedback.abort('Invalid host configuration specification: %s -- expected config_type:some;config;values' % config_specification)

        config_spec_parts = config_specification.split(':')

        return self._parse_config_spec(ConfigType(config_spec_parts[0]), config_spec_parts[-1].split(';'))

    def _invalid_host_config_format(self, config_specification):
        return config_specification.find(':') < 0

    def _parse_config_spec(self, config_type, config_parameters):
        if config_type.is_preconfigured():
            host_alias = config_parameters[0]
            if host_alias not in self.preconfigured_hosts:
                self.feedback.abort('No preconfigured values for host alias: %s' % host_alias)
            return self.preconfigured_hosts[host_alias]
        elif config_type.is_standard():
            return DeploymentHostConfig.create_with(config_parameters[0], config_parameters[1], config_parameters[2])
        elif config_type.is_custom():
            return self._custom_config_from(config_parameters[0])
        else:
            self.feedback.abort('Cannot parse host configuration from: %s:%s' % (config_type, ''.join(config_parameters)))

    def _custom_config_from(self, custom_config_module_path):
        import imp
        imp.load_source('custom_config', custom_config_module_path)
        from custom_config import CustomDeploymentHostConfig

        return CustomDeploymentHostConfig.create()
    def test_can_create_deployment_host_config_for_test2_host(self):
        """fab.tests.config.rsr.ci_deployment_host_config_test  Can create CI deployment host config for test2 host"""

        expected_test2_host_config = DeploymentHostConfig.create_with(HostAlias.TEST2, RepositoryBranch.DEVELOP, 'test2_rsrdb_develop')

        self.assertEqual(expected_test2_host_config, CIDeploymentHostConfig.for_test2())
    def test_can_parse_preconfigured_test2_host_config_from_given_task_parameters(self):
        """fab.tests.config.loader.deployment_config_loader_test  Can parse preconfigured test2 host configuration from given task parameters"""

        self.mox.ReplayAll()

        self.assertEqual(CIDeploymentHostConfig.for_test2(), self.config_loader.parse(self._preconfigured_config_spec_for(HostAlias.TEST2)))