Exemplo n.º 1
0
    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'])
Exemplo n.º 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"])
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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], "")
Exemplo n.º 6
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().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)
Exemplo n.º 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)
Exemplo n.º 8
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().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)
Exemplo n.º 9
0
    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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 16
0
 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)
Exemplo n.º 17
0
 def test_grain_pcre_targeting(self):
     args = self._base_args + ['-P', 'os:.*']
     resources = ResourceGenerator(args).run()
     self._test_attributes(resources, self.required_attributes)
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
 def test_glob_targeting(self):
     args = self._base_args + ['*']
     resources = ResourceGenerator(args).run()
     self._test_attributes(resources, self.required_attributes)
Exemplo n.º 20
0
 def test_os_arch_map2(self):
     os_arch = ResourceGenerator._os_arch('unknown')
     self.assertEqual(os_arch, 'unknown')
Exemplo n.º 21
0
 def test_os_arch_map1(self):
     os_arch = ResourceGenerator._os_arch('x86_64')
     self.assertEqual(os_arch, 'amd64')
Exemplo n.º 22
0
 def test_os_family_map2(self):
     os_family = ResourceGenerator._os_family('unknown')
     self.assertEqual(os_family, 'unknown')
Exemplo n.º 23
0
 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'])
Exemplo n.º 24
0
 def test_os_family_map1(self):
     os_family = ResourceGenerator._os_family("Linux")
     self.assertEqual(os_family, "unix")
Exemplo n.º 25
0
 def test_os_family_map1(self):
     os_family = ResourceGenerator._os_family('Linux')
     self.assertEqual(os_family, 'unix')
Exemplo n.º 26
0
 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)
Exemplo n.º 27
0
 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)
Exemplo n.º 28
0
 def test_os_arch_map2(self):
     os_arch = ResourceGenerator._os_arch("AMD64")
     self.assertEqual(os_arch, "amd64")
Exemplo n.º 29
0
 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)
Exemplo n.º 30
0
 def test_os_arch_map3(self):
     os_arch = ResourceGenerator._os_arch("unknown")
     self.assertEqual(os_arch, "unknown")