コード例 #1
0
    def test_init(self):
        # No host, returns False
        opts = {"proxy": {"username": "******", "password": "******"}}
        ret = cimc.init(opts)
        self.assertFalse(ret)

        # No username , returns False
        opts = {"proxy": {"password": "******", "host": "cimc"}}
        ret = cimc.init(opts)
        self.assertFalse(ret)

        # No password, returns False
        opts = {"proxy": {"username": "******", "host": "cimc"}}
        ret = cimc.init(opts)
        self.assertFalse(ret)

        with patch.object(cimc, "logon",
                          return_value="9zVG5U8DFZNsTR") as mock_logon:
            with patch.object(cimc,
                              "get_config_resolver_class",
                              return_value="True") as mock_logon:
                ret = cimc.init(self.opts)
                self.assertEqual(cimc.DETAILS["url"], "https://cimc/nuova")
                self.assertEqual(cimc.DETAILS["username"], "xxxx")
                self.assertEqual(cimc.DETAILS["password"], "xxx")
                self.assertTrue(cimc.DETAILS["initialized"])
コード例 #2
0
    def test_init(self):
        verify_ssl_values = (None, True, False)
        for verify_ssl_value in verify_ssl_values:
            cimc.DETAILS.clear()
            opts = {
                "proxy": {
                    "host": "TheHost",
                    "username": "******",
                    "password": "******",
                    "verify_ssl": verify_ssl_value,
                }
            }
            http_query_mock = MagicMock(side_effect=http_query_response)
            if verify_ssl_value is None:
                expected_verify_ssl_value = True
            else:
                expected_verify_ssl_value = verify_ssl_value

            log.debug(
                "verify_ssl: %s // expected verify_ssl: %s",
                verify_ssl_value,
                expected_verify_ssl_value,
            )

            with patch.dict(cimc.__utils__, {"http.query": http_query_mock}):
                cimc.init(opts)

            for idx, call in enumerate(http_query_mock.mock_calls, 1):
                condition = call.kwargs[
                    "verify_ssl"] is expected_verify_ssl_value
                condition_error = "{} != {}; Call(number={}): {}".format(
                    idx, call, call.kwargs["verify_ssl"],
                    expected_verify_ssl_value)
                self.assertTrue(condition, msg=condition_error)
コード例 #3
0
    def test_set_config_modify(self):
        verify_ssl_values = (None, True, False)
        for verify_ssl_value in verify_ssl_values:
            cimc.DETAILS.clear()
            opts = {
                "proxy": {
                    "host": "TheHost",
                    "username": "******",
                    "password": "******",
                    "verify_ssl": verify_ssl_value,
                }
            }
            http_query_mock = MagicMock(side_effect=http_query_response)
            if verify_ssl_value is None:
                expected_verify_ssl_value = True
            else:
                expected_verify_ssl_value = verify_ssl_value

            # Let's init the proxy and ignore it's actions, this test is not about them
            with patch(
                    "salt.proxy.cimc.get_config_resolver_class",
                    MagicMock(return_value=True),
            ):
                cimc.init(opts)

            log.debug(
                "verify_ssl: %s // expected verify_ssl: %s",
                verify_ssl_value,
                expected_verify_ssl_value,
            )

            with patch.dict(cimc.__utils__, {"http.query": http_query_mock}):
                cimc.set_config_modify(
                    dn="sys/rack-unit-1/locator-led",
                    inconfig=
                    ("<inConfig><equipmentLocatorLed adminState='on'"
                     " dn='sys/rack-unit-1/locator-led'></equipmentLocatorLed></inConfig>"
                     ),
                )

            for idx, call in enumerate(http_query_mock.mock_calls, 1):
                condition = call.kwargs[
                    "verify_ssl"] is expected_verify_ssl_value
                condition_error = "{} != {}; Call(number={}): {}".format(
                    idx, call, call.kwargs["verify_ssl"],
                    expected_verify_ssl_value)
                self.assertTrue(condition, msg=condition_error)