def test_init_from_current_configuration(self): self.init() conf = configuration.Configuration(configuration.CURRENT_CONFIGURATION) self.assertEqual(conf.configuration, configuration.CURRENT_CONFIGURATION) self.claw.generate(tests.STUB_CONFIGURATION) conf = configuration.Configuration(configuration.CURRENT_CONFIGURATION) self.assertEqual(conf.configuration, tests.STUB_CONFIGURATION)
def test_exists(self): self.init() conf = configuration.Configuration(tests.STUB_CONFIGURATION) self.assertFalse(conf.exists()) self.claw.generate(tests.STUB_CONFIGURATION) conf = configuration.Configuration(tests.STUB_CONFIGURATION) self.assertTrue(conf.exists()) blueprint = conf.blueprint(tests.STUB_BLUEPRINT) self.assertFalse(blueprint.exists()) self.claw('generate-blueprint', tests.STUB_CONFIGURATION, tests.STUB_BLUEPRINT) self.assertTrue(blueprint.exists())
def setUp(self): super(CleanupTest, self).setUp() with patcher.YamlPatcher(self.settings.user_suites_yaml) as patch: obj = patch.obj conf = obj['handler_configurations'][tests.STUB_CONFIGURATION] conf['handler'] = 'stub_handler' self.configuration = configuration.Configuration( tests.STUB_CONFIGURATION)
def _test(self, skip_generation=False, reset=False): requests_path = self.workdir / 'requests.json' port = self._start_server(requests_path) self.claw.generate(tests.STUB_CONFIGURATION) conf = configuration.Configuration(tests.STUB_CONFIGURATION) with conf.dir: sh.cfy.init() with cli_utils.update_wd_settings() as wd_settings: wd_settings.set_management_server('localhost') wd_settings.set_rest_port(port) blueprint_conf = conf.blueprint(tests.STUB_BLUEPRINT) if skip_generation or reset: self.claw('generate-blueprint', tests.STUB_CONFIGURATION, tests.STUB_BLUEPRINT) if skip_generation: with blueprint_conf.patch.inputs as patch: first_key = patch.obj.keys()[0] patch.obj[first_key] = 'SOME_OTHER_VALUE' # sanity if reset: with self.assertRaises(sh.ErrorReturnCode) as c: self.claw.deploy(tests.STUB_CONFIGURATION, tests.STUB_BLUEPRINT) self.assertIn('Already initialized', c.exception.stderr) self.claw.deploy(tests.STUB_CONFIGURATION, tests.STUB_BLUEPRINT, skip_generation=skip_generation, reset=reset) requests = json.loads(requests_path.text()) blueprint, deployment, execution = requests self.assertEqual(blueprint, {'blueprint': [tests.STUB_BLUEPRINT]}) self.assertEqual( deployment, { 'deployment': [ tests.STUB_BLUEPRINT, { 'blueprint_id': tests.STUB_BLUEPRINT, 'inputs': blueprint_conf.inputs } ] }) self.assertEqual( execution, { 'execution': [{ 'deployment_id': tests.STUB_BLUEPRINT, 'parameters': None, 'allow_custom_parameters': 'false', 'workflow_id': 'install', 'force': 'false' }] })
def test_no_connectivity_to_manager(self): self.claw.generate(tests.STUB_CONFIGURATION) conf = configuration.Configuration(tests.STUB_CONFIGURATION) ip = '127.0.0.1' with conf.patch.handler_configuration as patch: patch.set_value('manager_ip', ip) with self.assertRaises(sh.ErrorReturnCode) as c: self.claw.status(tests.STUB_CONFIGURATION) self.assertIn('Not reachable', c.exception.stderr) self.assertIn(ip, c.exception.stderr)
def test_basic(self): test_version = 'TEST_VERSION' port = self.server({'version': lambda: {'version': test_version}}) self.claw.generate(tests.STUB_CONFIGURATION) conf = configuration.Configuration(tests.STUB_CONFIGURATION) with conf.patch.handler_configuration as patch: patch.set_value('manager_ip', 'localhost') patch.set_value('manager_port', port) output = self.claw.status(tests.STUB_CONFIGURATION).stdout self.assertIn(test_version, output)
def assert_files(obj, files): content = {'some': 'value'} for _file in files: setattr(obj, _file[0], content) if isinstance(obj, configuration.Configuration): new_obj = configuration.Configuration(tests.STUB_CONFIGURATION) else: new_obj = conf.blueprint(tests.STUB_BLUEPRINT) for _file in files: self.assertEqual(content, getattr(new_obj, _file[0])) self.assertEqual(yaml.safe_load(_file[1].text()), content)
def _test(self, reset=False): user = '******' ip = 'my_host' key = 'my_key' configuration_name = 'conf' blueprint_dir = path(resources.DIR) / 'mock-manager-blueprint' blueprint_path = blueprint_dir / 'manager-blueprint.yaml' handler_configuration = {'manager_blueprint': str(blueprint_path)} suites_yaml = { 'manager_blueprint_override_templates': { 'mock_blueprint1': { 'node_templates.manager_configuration.type': 'cloudify.nodes.MyCloudifyManager' }, 'mock_blueprint2': { 'node_templates.manager_configuration.interfaces.' 'cloudify\.interfaces\.lifecycle.configure.implementation': 'configure.py' } }, 'inputs_override_templates': { 'mock_inputs1': { 'user': user, 'key_filename': key, }, 'mock_inputs2': { 'ip': ip, 'rest_port': 80 } }, 'handler_configurations': { configuration_name: handler_configuration } } self.settings.user_suites_yaml.write_text(yaml.safe_dump(suites_yaml)) self.claw.bootstrap(configuration_name, '-i', 'mock_inputs1', '-i', 'mock_inputs2', '-b', 'mock_blueprint1', '-b', 'mock_blueprint2', reset=reset) conf = configuration.Configuration(configuration_name) self.assertTrue(conf.cli_config['colors']) self.assertEqual(conf.handler_configuration['manager_ip'], ip) self.assertEqual(conf.handler_configuration['manager_user'], user) self.assertEqual(conf.handler_configuration['manager_key'], key) return configuration_name
def _test(self, inputs=None, inputs_override=None, processed_inputs_override=None, blueprint_override=None, processed_blueprint_override=None, properties=None, reset=False, skip_conf_generate=False): configuration_name = 'conf1' blueprint_name = 'blueprint1' properties_name = 'some_properties' if not skip_conf_generate: main_suites_yaml = { 'handler_properties': { properties_name: properties or {} } } main_suites_yaml_path = self.workdir / 'main-suites.yaml' main_suites_yaml_path.write_text(yaml.safe_dump(main_suites_yaml)) self.init(main_suites_yaml_path) conf = configuration.Configuration(configuration_name) blueprint_dir = self.workdir / 'blueprint' blueprint_dir.mkdir_p() manager_blueprint_path = blueprint_dir / 'manager-blueprint.yaml' inputs_path = blueprint_dir / 'inputs.yaml' blueprint_path = blueprint_dir / 'some-blueprint.yaml' new_blueprint_dir = conf.dir / 'blueprints' / blueprint_name new_inputs_path = new_blueprint_dir / 'inputs.yaml' new_blueprint_path = (new_blueprint_dir / 'blueprint' / 'blueprint.yaml') blueprint_configuration_path = (new_blueprint_dir / 'blueprint-configuration.yaml') manager_blueprint = {'some': 'manager_blueprint'} blueprint = {'some_user': '******'} if inputs: inputs_path.write_text(yaml.safe_dump(inputs)) blueprint_path.write_text(yaml.safe_dump(blueprint)) manager_blueprint_path.write_text(yaml.safe_dump(manager_blueprint)) blueprint_configuration = {'blueprint': str(blueprint_path)} if inputs: blueprint_configuration['inputs'] = str(inputs_path) if inputs_override: blueprint_configuration['inputs_override'] = inputs_override if blueprint_override: blueprint_configuration['blueprint_override'] = blueprint_override user_suites_yaml = { 'handler_configurations': { configuration_name: { 'manager_blueprint': str(manager_blueprint_path), 'properties': properties_name } } } blueprints_yaml = { 'variables': self.variables, 'blueprints': { blueprint_name: blueprint_configuration } } self.settings.user_suites_yaml.write_text( yaml.safe_dump(user_suites_yaml)) self.settings.blueprints_yaml.write_text( yaml.safe_dump(blueprints_yaml)) if not skip_conf_generate: self.claw.generate(configuration_name) self.claw('generate-blueprint', configuration_name, blueprint_name, reset=reset) expected_inputs = (inputs or {}).copy() expected_inputs.update((processed_inputs_override or {})) self.assertEqual(expected_inputs, yaml.safe_load(new_inputs_path.text())) expected_blueprint = blueprint.copy() expected_blueprint.update((processed_blueprint_override or {})) self.assertEqual(expected_blueprint, yaml.safe_load(new_blueprint_path.text())) expected_blueprint_configuration = blueprint_configuration.copy() expected_blueprint_configuration.pop('inputs_override', {}) expected_blueprint_configuration.pop('blueprint_override', {}) expected_blueprint_configuration.update({ 'blueprint': new_blueprint_path, 'inputs': new_inputs_path }) self.assertEqual(expected_blueprint_configuration, yaml.safe_load(blueprint_configuration_path.text())) self.assertEqual(blueprints_yaml, yaml.safe_load(self.settings.blueprints_yaml.text()))
def test_init_from_current_dir(self): conf = configuration.Configuration() self.assertEqual(conf.configuration, path(os.getcwd()).basename())
def test_init_from_dir(self): conf = configuration.Configuration(self.workdir) self.assertEqual(conf.configuration, self.workdir.basename())
def _init_configuration(self, suites_yaml=None): self.init(suites_yaml) self.claw.generate(tests.STUB_CONFIGURATION) return configuration.Configuration(tests.STUB_CONFIGURATION)
def test_basic(self): configuration_name = self._test() conf = configuration.Configuration(configuration_name) self.claw.teardown(configuration_name) self.assertEqual('delete invoked', (conf.dir / 'delete.output').text())