Exemplo n.º 1
0
 def test_merge(self):
     mock_pillar_proxy = MagicMock()
     mock_opts_proxy = MagicMock()
     mock_merge = MagicMock(return_value=self.opts_sspi["proxy"])
     with patch.dict(esxcluster.__pillar__, {"proxy": mock_pillar_proxy}):
         with patch("salt.proxy.esxcluster.merge", mock_merge):
             esxcluster.init(opts={"proxy": mock_opts_proxy})
     mock_merge.assert_called_once_with(mock_opts_proxy, mock_pillar_proxy)
Exemplo n.º 2
0
 def test_esxcluster_schema(self):
     mock_json_validate = MagicMock()
     serialized_schema = EsxclusterProxySchema().serialize()
     with patch("salt.proxy.esxcluster.jsonschema.validate",
                mock_json_validate):
         esxcluster.init(self.opts_sspi)
     mock_json_validate.assert_called_once_with(self.opts_sspi["proxy"],
                                                serialized_schema)
Exemplo n.º 3
0
 def test_find_credentials(self):
     mock_find_credentials = MagicMock(return_value=('fake_username',
                                                     'fake_password'))
     with patch('salt.proxy.esxcluster.merge',
                MagicMock(return_value=self.opts_userpass['proxy'])):
         with patch('salt.proxy.esxcluster.find_credentials',
                    mock_find_credentials):
             esxcluster.init(self.opts_userpass)
     mock_find_credentials.assert_called_once_with()
Exemplo n.º 4
0
 def test_invalid_proxy_input_error(self):
     with patch(
             'salt.proxy.esxcluster.jsonschema.validate',
             MagicMock(side_effect=jsonschema.exceptions.ValidationError(
                 'Validation Error'))):
         with self.assertRaises(salt.exceptions.InvalidConfigError) as \
                 excinfo:
             esxcluster.init(self.opts_userpass)
     self.assertEqual(excinfo.exception.strerror, 'Validation Error')
Exemplo n.º 5
0
 def test_find_credentials(self):
     mock_find_credentials = MagicMock(return_value=("fake_username",
                                                     "fake_password"))
     with patch(
             "salt.proxy.esxcluster.merge",
             MagicMock(return_value=self.opts_userpass["proxy"]),
     ):
         with patch("salt.proxy.esxcluster.find_credentials",
                    mock_find_credentials):
             esxcluster.init(self.opts_userpass)
     mock_find_credentials.assert_called_once_with()
Exemplo n.º 6
0
 def test_no_principal(self):
     opts = self.opts_sspi.copy()
     del opts['proxy']['principal']
     with patch('salt.proxy.esxcluster.merge',
                MagicMock(return_value=opts['proxy'])):
         with self.assertRaises(salt.exceptions.InvalidConfigError) as \
                 excinfo:
             esxcluster.init(opts)
     self.assertEqual(
         excinfo.exception.strerror, 'Mechanism is set to \'sspi\', but no '
         '\'principal\' key found in proxy config.')
Exemplo n.º 7
0
 def test_details_sspi(self):
     esxcluster.init(self.opts_sspi)
     self.assertDictEqual(esxcluster.DETAILS,
                          {'vcenter': 'fake_vcenter',
                           'datacenter': 'fake_dc',
                           'cluster': 'fake_cluster',
                           'mechanism': 'sspi',
                           'domain': 'fake_domain',
                           'principal': 'fake_principal',
                           'protocol': 'fake_protocol',
                           'port': 100})
Exemplo n.º 8
0
 def test_no_principal(self):
     opts = self.opts_sspi.copy()
     del opts["proxy"]["principal"]
     with patch("salt.proxy.esxcluster.merge",
                MagicMock(return_value=opts["proxy"])):
         with self.assertRaises(
                 salt.exceptions.InvalidConfigError) as excinfo:
             esxcluster.init(opts)
     self.assertEqual(
         excinfo.exception.strerror,
         "Mechanism is set to 'sspi', but no 'principal' key found in proxy config.",
     )
Exemplo n.º 9
0
 def test_details_sspi(self):
     esxcluster.init(self.opts_sspi)
     self.assertDictEqual(
         esxcluster.DETAILS,
         {
             "vcenter": "fake_vcenter",
             "datacenter": "fake_dc",
             "cluster": "fake_cluster",
             "mechanism": "sspi",
             "domain": "fake_domain",
             "principal": "fake_principal",
             "protocol": "fake_protocol",
             "port": 100,
         },
     )
Exemplo n.º 10
0
 def test_details_userpass(self):
     mock_find_credentials = MagicMock(return_value=('fake_username',
                                                     'fake_password'))
     with patch('salt.proxy.esxcluster.merge',
                MagicMock(return_value=self.opts_userpass['proxy'])):
         with patch('salt.proxy.esxcluster.find_credentials',
                    mock_find_credentials):
             esxcluster.init(self.opts_userpass)
     self.assertDictEqual(esxcluster.DETAILS,
                          {'vcenter': 'fake_vcenter',
                           'datacenter': 'fake_dc',
                           'cluster': 'fake_cluster',
                           'mechanism': 'userpass',
                           'username': '******',
                           'password': '******',
                           'passwords': ['fake_password'],
                           'protocol': 'fake_protocol',
                           'port': 100})
Exemplo n.º 11
0
 def test_details_userpass(self):
     mock_find_credentials = MagicMock(return_value=("fake_username",
                                                     "fake_password"))
     with patch(
             "salt.proxy.esxcluster.merge",
             MagicMock(return_value=self.opts_userpass["proxy"]),
     ):
         with patch("salt.proxy.esxcluster.find_credentials",
                    mock_find_credentials):
             esxcluster.init(self.opts_userpass)
     self.assertDictEqual(
         esxcluster.DETAILS,
         {
             "vcenter": "fake_vcenter",
             "datacenter": "fake_dc",
             "cluster": "fake_cluster",
             "mechanism": "userpass",
             "username": "******",
             "password": "******",
             "passwords": ["fake_password"],
             "protocol": "fake_protocol",
             "port": 100,
         },
     )