コード例 #1
0
ファイル: test.py プロジェクト: contherad/salt-gen-resource
    def _test_required_attributes(self, resources):
        self.assertTrue(len(resources) > 0)
        for host, attributes in resources.iteritems():
            for attribute in self.required_attributes:
                self.assertIn(attribute, attributes)
                self.assertIsNotNone(attributes[attribute])
                self.assertNotEqual(attributes[attribute], '')

            if host == ResourceGenerator._server_node_name:
                expected = self.server_grains
                self.assertIn(host, resources)
                self.assertEqual(resources[host]['hostname'], host)
            else:
                expected = self.mine[host]
                self.assertIn(host, resources)
                self.assertEqual(
                    resources[host]['hostname'],
                    expected['fqdn'])

            self.assertEqual(
                resources[host]['osArch'],
                ResourceGenerator._os_arch(expected['cpuarch']))
            self.assertEqual(
                resources[host]['osFamily'],
                ResourceGenerator._os_family(expected['kernel']))
            self.assertEqual(
                resources[host]['osName'],
                expected['kernel'])
            self.assertEqual(
                resources[host]['osVersion'],
                expected['kernelrelease'])
コード例 #2
0
    def _test_required_attributes(self, resources):
        self.assertTrue(len(resources) > 0)
        for host, attributes in six.iteritems(resources):
            for attribute in self.required_attributes:
                self.assertIn(attribute, attributes)
                self.assertIsNotNone(attributes[attribute])
                self.assertNotEqual(attributes[attribute], "")

            if host == ResourceGenerator._server_node_name:
                expected = self.server_grains
                self.assertIn(host, resources)
                self.assertEqual(resources[host]["hostname"], host)
            else:
                expected = self.mine[host]
                self.assertIn(host, resources)
                self.assertEqual(resources[host]["hostname"], expected["fqdn"])

            self.assertEqual(
                resources[host]["osArch"],
                ResourceGenerator._os_arch(expected["cpuarch"]),
            )
            self.assertEqual(
                resources[host]["osFamily"],
                ResourceGenerator._os_family(expected["kernel"]),
            )
            self.assertEqual(resources[host]["osName"], expected["kernel"])
            self.assertEqual(resources[host]["osVersion"],
                             expected["kernelrelease"])
コード例 #3
0
 def _test_tags(self, resources, needed):
     self.assertTrue(len(resources) > 0)
     self.assertNotIn("!!", ResourceGenerator._dump_yaml(resources))
     for _, attributes in six.iteritems(resources):
         self.assertIn("tags", attributes)
         self.assertIsNotNone(attributes["tags"])
         self.assertEqual(len(attributes["tags"]), len(needed))
コード例 #4
0
 def _test_tags(self, resources, needed):
     self.assertTrue(len(resources) > 0)
     self.assertNotIn('!!', ResourceGenerator._dump_yaml(resources))
     for host, attributes in six.iteritems(resources):
         self.assertIn('tags', attributes)
         self.assertIsNotNone(attributes['tags'])
         self.assertEqual(len(attributes['tags']), len(needed))
コード例 #5
0
 def _test_attributes(self, resources, needed):
     self.assertTrue(len(resources) > 0)
     self.assertNotIn("!!", ResourceGenerator._dump_yaml(resources))
     for _, attributes in six.iteritems(resources):
         for attribute in needed:
             self.assertIn(attribute, attributes)
             self.assertIsNotNone(attributes[attribute])
             self.assertNotEqual(attributes[attribute], "")
コード例 #6
0
ファイル: test.py プロジェクト: contherad/salt-gen-resource
    def test_static_attributes(self):
        with patch('SaltGenResource.SaltNodesCommandParser', MockParser()) as parser:
            with patch('salt.client.Caller', MockCaller()) as caller:
                call_kwargs = dict.copy(self.default_kwargs)
                parser.options.include_server_node = self.include_server_node
                call_kwargs['exclude_minion'] = self.include_server_node

                parser.args = ['color=yellow', 'pattern=\'polka dot\'']
                resources = ResourceGenerator().run()

                self._test_required_attributes(resources)
                self._test_attributes(resources, ['color', 'pattern'])

                for host, attributes in resources.iteritems():
                    self.assertEqual(resources[host]['color'], 'yellow')
                    self.assertEqual(resources[host]['pattern'], 'polka dot')

                caller.cmd.assert_called_once_with(*self.default_args, **call_kwargs)
コード例 #7
0
    def test_unicode(self):
        with patch("SaltGenResource.SaltNodesCommandParser",
                   MockParser()) as parser:
            with patch("salt.client.Caller", MockCaller()):
                call_kwargs = dict.copy(self.default_kwargs)
                parser.options.include_server_node = self.include_server_node
                call_kwargs["exclude_minion"] = self.include_server_node

                parser.args = [u"color=⋐⊮⊰⟒"]
                output = ResourceGenerator().as_yaml()
                self.assertNotIn("!!python/unicode", output)
コード例 #8
0
ファイル: test.py プロジェクト: contherad/salt-gen-resource
    def test_static_username(self):
        with patch('SaltGenResource.SaltNodesCommandParser', MockParser()) as parser:
            with patch('salt.client.Caller', MockCaller()) as caller:
                call_kwargs = dict.copy(self.default_kwargs)
                parser.options.include_server_node = self.include_server_node
                call_kwargs['exclude_minion'] = self.include_server_node

                parser.args = ['username=root']
                resources = ResourceGenerator().run()

                self._test_required_attributes(resources)
                self._test_attributes(resources, ['username'])

                for host, attributes in resources.iteritems():
                    if host == ResourceGenerator._server_node_name:
                        self.assertEqual(resources[host]['username'], parser.options.server_node_user)
                    else:
                        self.assertEqual(resources[host]['username'], 'root')

                caller.cmd.assert_called_once_with(*self.default_args, **call_kwargs)
コード例 #9
0
ファイル: test.py プロジェクト: contherad/salt-gen-resource
    def test_multiple_tags(self):
        with patch('SaltGenResource.SaltNodesCommandParser', MockParser()) as parser:
            with patch('salt.client.Caller', MockCaller()) as caller:
                call_kwargs = dict.copy(self.default_kwargs)
                parser.options.include_server_node = self.include_server_node
                call_kwargs['exclude_minion'] = self.include_server_node

                parser.options.tags = ['os', 'kernelrelease']
                resources = ResourceGenerator().run()

                self._test_required_attributes(resources)
                self._test_tags(resources, parser.options.tags)
                caller.cmd.assert_called_once_with(*self.default_args, **call_kwargs)
コード例 #10
0
    def test_single_tag(self):
        with patch("SaltGenResource.SaltNodesCommandParser",
                   MockParser()) as parser:
            with patch("salt.client.Caller", MockCaller()) as caller:
                call_kwargs = dict.copy(self.default_kwargs)
                parser.options.include_server_node = self.include_server_node
                call_kwargs["exclude_minion"] = self.include_server_node

                parser.options.tags = ["os"]
                resources = ResourceGenerator().as_dict()

                self._test_required_attributes(resources)
                self._test_tags(resources, parser.options.tags)
                caller.cmd.assert_called_once_with(*self.default_args,
                                                   **call_kwargs)
コード例 #11
0
    def test_list_tag(self):
        with patch("SaltGenResource.SaltNodesCommandParser",
                   MockParser()) as parser:
            with patch("salt.client.Caller", MockCaller()) as caller:
                call_kwargs = dict.copy(self.default_kwargs)
                parser.options.include_server_node = self.include_server_node
                call_kwargs["exclude_minion"] = self.include_server_node

                parser.options.tags = ["colors"]
                resources = ResourceGenerator().as_dict()

                self._test_required_attributes(resources)
                caller.cmd.assert_called_once_with(*self.default_args,
                                                   **call_kwargs)

                for _, attributes in six.iteritems(resources):
                    self.assertTrue(len(attributes["tags"]) > 1)
コード例 #12
0
    def test_falsy_attribute(self):
        with patch("SaltGenResource.SaltNodesCommandParser",
                   MockParser()) as parser:
            with patch("salt.client.Caller", MockCaller()) as caller:

                call_kwargs = dict.copy(self.default_kwargs)
                parser.options.include_server_node = self.include_server_node
                call_kwargs["exclude_minion"] = self.include_server_node

                parser.options.attributes = ["virtual"]
                resources = ResourceGenerator().as_dict()

                self._test_required_attributes(resources)
                self._test_attributes(resources, parser.options.attributes)
                caller.cmd.assert_called_once_with(*self.default_args,
                                                   **call_kwargs)

                for _, resource in six.iteritems(resources):
                    self.assertIs(resource["virtual"], False)
コード例 #13
0
    def test_list_attribute(self):
        with patch('SaltGenResource.SaltNodesCommandParser',
                   MockParser()) as parser:
            with patch('salt.client.Caller', MockCaller()) as caller:

                call_kwargs = dict.copy(self.default_kwargs)
                parser.options.include_server_node = self.include_server_node
                call_kwargs['exclude_minion'] = self.include_server_node

                parser.options.attributes = ['colors']
                resources = ResourceGenerator().as_dict()

                self._test_required_attributes(resources)
                self._test_attributes(resources, parser.options.attributes)
                caller.cmd.assert_called_once_with(*self.default_args,
                                                   **call_kwargs)

                for minion, resource in six.iteritems(resources):
                    self.assertEqual(resource['colors'], 'red')
コード例 #14
0
    def test_static_attributes(self):
        with patch("SaltGenResource.SaltNodesCommandParser",
                   MockParser()) as parser:
            with patch("salt.client.Caller", MockCaller()) as caller:
                call_kwargs = dict.copy(self.default_kwargs)
                parser.options.include_server_node = self.include_server_node
                call_kwargs["exclude_minion"] = self.include_server_node

                parser.args = ["color=yellow", "pattern='polka dot'"]
                resources = ResourceGenerator().as_dict()

                self._test_required_attributes(resources)
                self._test_attributes(resources, ["color", "pattern"])

                for host, _ in six.iteritems(resources):
                    self.assertEqual(resources[host]["color"], "yellow")
                    self.assertEqual(resources[host]["pattern"], "polka dot")

                caller.cmd.assert_called_once_with(*self.default_args,
                                                   **call_kwargs)
コード例 #15
0
    def test_static_username(self):
        with patch("SaltGenResource.SaltNodesCommandParser",
                   MockParser()) as parser:
            with patch("salt.client.Caller", MockCaller()) as caller:
                call_kwargs = dict.copy(self.default_kwargs)
                parser.options.include_server_node = self.include_server_node
                call_kwargs["exclude_minion"] = self.include_server_node

                parser.args = ["username=root"]
                resources = ResourceGenerator().as_dict()

                self._test_required_attributes(resources)
                self._test_attributes(resources, ["username"])

                for host, _ in six.iteritems(resources):
                    if host == ResourceGenerator._server_node_name:
                        self.assertEqual(resources[host]["username"],
                                         parser.options.server_node_user)
                    else:
                        self.assertEqual(resources[host]["username"], "root")

                caller.cmd.assert_called_once_with(*self.default_args,
                                                   **call_kwargs)
コード例 #16
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_single_attribute(self):
     optional_attributes = ['os']
     args = self._base_args + ['-a', optional_attributes[0], '*']
     resources = ResourceGenerator(args).run()
     self._test_attributes(resources, self.required_attributes)
     self._test_attributes(resources, optional_attributes)
コード例 #17
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_grain_pcre_targeting(self):
     args = self._base_args + ['-P', 'os:.*']
     resources = ResourceGenerator(args).run()
     self._test_attributes(resources, self.required_attributes)
コード例 #18
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_cidr_targeting(self):
     args = self._base_args + ['-S', '0.0.0.0/0']
     resources = ResourceGenerator(args).run()
     self._test_attributes(resources, self.required_attributes)
コード例 #19
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_glob_targeting(self):
     args = self._base_args + ['*']
     resources = ResourceGenerator(args).run()
     self._test_attributes(resources, self.required_attributes)
コード例 #20
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_os_arch_map2(self):
     os_arch = ResourceGenerator._os_arch('unknown')
     self.assertEqual(os_arch, 'unknown')
コード例 #21
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_os_arch_map1(self):
     os_arch = ResourceGenerator._os_arch('x86_64')
     self.assertEqual(os_arch, 'amd64')
コード例 #22
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_os_family_map2(self):
     os_family = ResourceGenerator._os_family('unknown')
     self.assertEqual(os_family, 'unknown')
コード例 #23
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_static_attributes(self):
     args = self._base_args + ['*', 'username=root', 'password=\'pw\'']
     resources = ResourceGenerator(args).run()
     self._test_attributes(resources, self.required_attributes)
     self._test_attributes(resources, ['username', 'password'])
コード例 #24
0
 def test_os_family_map1(self):
     os_family = ResourceGenerator._os_family("Linux")
     self.assertEqual(os_family, "unix")
コード例 #25
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_os_family_map1(self):
     os_family = ResourceGenerator._os_family('Linux')
     self.assertEqual(os_family, 'unix')
コード例 #26
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_multiple_attributes2(self):
     optional_attributes = ['os', 'os_family']
     args = self._base_args + ['-a', ','.join(optional_attributes), '*']
     resources = ResourceGenerator(args).run()
     self._test_attributes(resources, self.required_attributes)
     self._test_attributes(resources, optional_attributes)
コード例 #27
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_single_tag(self):
     tags = ['os']
     args = self._base_args + ['-t', tags[0], '*']
     resources = ResourceGenerator(args).run()
     self._test_attributes(resources, self.required_attributes)
     self._test_tags(resources, tags)
コード例 #28
0
 def test_os_arch_map2(self):
     os_arch = ResourceGenerator._os_arch("AMD64")
     self.assertEqual(os_arch, "amd64")
コード例 #29
0
ファイル: test.py プロジェクト: SolarisYan/salt-gen-resource
 def test_multiple_tags1(self):
     tags = ['os', 'os_family']
     args = self._base_args + ['-t', ','.join(tags), '*']
     resources = ResourceGenerator(args).run()
     self._test_attributes(resources, self.required_attributes)
     self._test_tags(resources, tags)
コード例 #30
0
 def test_os_arch_map3(self):
     os_arch = ResourceGenerator._os_arch("unknown")
     self.assertEqual(os_arch, "unknown")