コード例 #1
0
ファイル: __init__.py プロジェクト: xuanhan863/cdist
 def test_list_objects(self):
     objects = list(
         core.Object.list_objects(object_base_path, type_base_path))
     objects_expected = [
         core.Object(core.Type(type_base_path, '__first'), object_base_path,
                     'man'),
         core.Object(core.Type(type_base_path, '__second'),
                     object_base_path, 'on-the'),
         core.Object(core.Type(type_base_path, '__third'), object_base_path,
                     'moon'),
     ]
     self.assertEqual(objects, objects_expected)
コード例 #2
0
 def test_run_type_explorers(self):
     cdist_type = core.Type(self.local.type_path, '__test_type')
     cdist_object = core.Object(cdist_type, self.local.object_path,
                                'whatever')
     cdist_object.create()
     self.explorer.run_type_explorers(cdist_object)
     self.assertEqual(cdist_object.explorers, {'world': 'hello'})
コード例 #3
0
    def setup_object(self):
        # FIXME: verify object id

        # Setup object_id
        if self.cdist_type.is_singleton:
            self.object_id = "singleton"
        else:
            self.object_id = self.args.object_id[0]
            del self.args.object_id

            # strip leading slash from object_id
            self.object_id = self.object_id.lstrip('/')

        # Instantiate the cdist object we are defining
        self.cdist_object = core.Object(self.cdist_type, self.object_base_path,
                                        self.object_id)

        # Create object with given parameters
        self.parameters = {}
        for key, value in vars(self.args).items():
            if value is not None:
                self.parameters[key] = value

        if self.cdist_object.exists:
            if self.cdist_object.parameters != self.parameters:
                raise cdist.Error(
                    "Object %s already exists with conflicting parameters:\n%s: %s\n%s: %s"
                    % (self.cdist_object, " ".join(self.cdist_object.source),
                       self.cdist_object.parameters, self.object_source,
                       self.parameters))
        else:
            self.cdist_object.create()
            self.cdist_object.parameters = self.parameters
コード例 #4
0
 def test_run_type_explorer(self):
     cdist_type = core.Type(self.local.type_path, '__test_type')
     cdist_object = core.Object(cdist_type, self.local.object_path,
                                'whatever')
     self.explorer.transfer_type_explorers(cdist_type)
     output = self.explorer.run_type_explorer('world', cdist_object)
     self.assertEqual(output, 'hello\n')
コード例 #5
0
ファイル: __init__.py プロジェクト: xuanhan863/cdist
 def test_autorequire(self):
     initial_manifest = os.path.join(self.local.manifest_path, "init")
     self.manifest.run_initial_manifest(initial_manifest)
     cdist_type = core.Type(self.local.type_path, '__saturn')
     cdist_object = core.Object(cdist_type, self.local.object_path, 'singleton')
     self.manifest.run_type_manifest(cdist_object)
     expected = ['__planet/Saturn', '__moon/Prometheus']
     self.assertEqual(sorted(cdist_object.requirements), sorted(expected))
コード例 #6
0
ファイル: __init__.py プロジェクト: xuanhan863/cdist
    def test_arguments_with_dashes(self):
        argv = ['__arguments_with_dashes', 'some-id', '--with-dash', 'some value']
        os.environ.update(self.env)
        emu = emulator.Emulator(argv)
        emu.run()

        cdist_type = core.Type(self.local.type_path, '__arguments_with_dashes')
        cdist_object = core.Object(cdist_type, self.local.object_path, 'some-id')
        self.assertTrue('with-dash' in cdist_object.parameters)
コード例 #7
0
 def test_transfer_object_parameters(self):
     cdist_type = core.Type(self.local.type_path, '__test_type')
     cdist_object = core.Object(cdist_type, self.local.object_path,
                                'whatever')
     cdist_object.create()
     cdist_object.parameters = {
         'first': 'first value',
         'second': 'second value'
     }
     self.explorer.transfer_object_parameters(cdist_object)
     source = os.path.join(self.local.object_path,
                           cdist_object.parameter_path)
     destination = os.path.join(self.remote.object_path,
                                cdist_object.parameter_path)
     self.assertEqual(sorted(os.listdir(source)),
                      sorted(os.listdir(destination)))
コード例 #8
0
    def record_requirements(self):
        """record requirements"""

        if "require" in os.environ:
            requirements = os.environ['require']
            self.log.debug("reqs = " + requirements)
            for requirement in requirements.split(" "):
                # Ignore empty fields - probably the only field anyway
                if len(requirement) == 0:
                    continue

                self.log.debug("Recording requirement: " + requirement)
                requirement_parts = requirement.split(os.sep, 1)
                requirement_type_name = requirement_parts[0]
                try:
                    requirement_object_id = requirement_parts[1]
                except IndexError:
                    # no object id, assume singleton
                    requirement_object_id = 'singleton'

                # Remove leading / from object id
                requirement_object_id = requirement_object_id.lstrip('/')

                # Instantiate type which fails if type does not exist
                requirement_type = core.Type(self.type_base_path,
                                             requirement_type_name)

                if requirement_object_id == 'singleton' \
                    and not requirement_type.is_singleton:
                    raise IllegalRequirementError(
                        requirement,
                        "Missing object_id and type is not a singleton.")

                # Instantiate object which fails if the object_id is illegal
                requirement_object = core.Object(requirement_type,
                                                 self.object_base_path,
                                                 requirement_object_id)

                # Construct cleaned up requirement with only one / :-)
                requirement = requirement_type_name + '/' + requirement_object_id
                self.cdist_object.requirements.append(requirement)

        # Record / Append source
        self.cdist_object.source.append(self.object_source)
コード例 #9
0
    def setUp(self):
        self.target_host = 'localhost'

        self.local_base_path = local_base_path
        self.out_path = self.mkdtemp()
        self.local = local.Local(self.target_host, self.local_base_path,
                                 self.out_path)
        self.local.create_directories()

        self.remote_base_path = self.mkdtemp()
        self.user = getpass.getuser()
        remote_exec = "ssh -o User=%s -q" % self.user
        remote_copy = "scp -o User=%s -q" % self.user
        self.remote = remote.Remote(self.target_host, self.remote_base_path,
                                    remote_exec, remote_copy)

        self.code = code.Code(self.target_host, self.local, self.remote)

        self.cdist_type = core.Type(self.local.type_path, '__dump_environment')
        self.cdist_object = core.Object(self.cdist_type,
                                        self.local.object_path, 'whatever')
        self.cdist_object.create()

        self.log = logging.getLogger("cdist")
コード例 #10
0
ファイル: __init__.py プロジェクト: xuanhan863/cdist
    def test_type_manifest_environment(self):
        cdist_type = core.Type(self.local.type_path, '__dump_environment')
        cdist_object = core.Object(cdist_type, self.local.object_path, 'whatever')
        handle, output_file = self.mkstemp(dir=self.temp_dir)
        os.close(handle)
        os.environ['__cdist_test_out'] = output_file
        self.manifest.run_type_manifest(cdist_object)

        with open(output_file, 'r') as fd:
            output_string = fd.read()
        output_dict = {}
        for line in output_string.split('\n'):
            if line:
                key,value = line.split(': ')
                output_dict[key] = value
        self.assertTrue(output_dict['PATH'].startswith(self.local.bin_path))
        self.assertEqual(output_dict['__target_host'], self.local.target_host)
        self.assertEqual(output_dict['__global'], self.local.out_path)
        self.assertEqual(output_dict['__cdist_type_base_path'], self.local.type_path)
        self.assertEqual(output_dict['__type'], cdist_type.absolute_path)
        self.assertEqual(output_dict['__object'], cdist_object.absolute_path)
        self.assertEqual(output_dict['__object_id'], cdist_object.object_id)
        self.assertEqual(output_dict['__object_name'], cdist_object.name)
        self.assertEqual(output_dict['__self'], cdist_object.name)
コード例 #11
0
ファイル: __init__.py プロジェクト: xuanhan863/cdist
 def setUp(self):
     self.cdist_type = core.Type(type_base_path, '__third')
     self.cdist_object = core.Object(self.cdist_type, object_base_path,
                                     'moon')
コード例 #12
0
ファイル: __init__.py プロジェクト: xuanhan863/cdist
 def test_object_id_contains_object_marker_string(self):
     cdist_type = core.Type(type_base_path, '__third')
     illegal_object_id = 'object_id/may/contain_%s_in_filename' % core.OBJECT_MARKER
     core.Object(cdist_type, object_base_path, illegal_object_id)
コード例 #13
0
ファイル: __init__.py プロジェクト: xuanhan863/cdist
 def test_object_id_contains_object_marker(self):
     cdist_type = core.Type(type_base_path, '__third')
     illegal_object_id = 'object_id/may/not/contain/%s/anywhere' % core.OBJECT_MARKER
     with self.assertRaises(core.IllegalObjectIdError):
         core.Object(cdist_type, object_base_path, illegal_object_id)
コード例 #14
0
ファイル: __init__.py プロジェクト: xuanhan863/cdist
 def test_object_id_starts_with_slash(self):
     cdist_type = core.Type(type_base_path, '__third')
     illegal_object_id = '/object_id/may/not/start/with/slash'
     with self.assertRaises(core.IllegalObjectIdError):
         core.Object(cdist_type, object_base_path, illegal_object_id)