Esempio n. 1
0
 def test_list_datacenters(self):
     mock_list_datacenters = MagicMock()
     with patch.dict(
             esxdatacenter.__salt__,
         {'vsphere.list_datacenters_via_proxy': mock_list_datacenters}):
         esxdatacenter.datacenter_configured('fake_dc')
     mock_list_datacenters.assert_called_once_with(
         datacenter_names=['fake_dc'], service_instance=self.mock_si)
Esempio n. 2
0
 def test_get_service_instance(self):
     mock_get_service_instance = MagicMock()
     with patch.dict(esxdatacenter.__salt__, {
             'vsphere.get_service_instance_via_proxy':
             mock_get_service_instance
     }):
         esxdatacenter.datacenter_configured('fake_dc')
     mock_get_service_instance.assert_called_once_with()
 def test_create_datacenter(self):
     mock_create_datacenter = MagicMock()
     with patch.dict(
             esxdatacenter.__salt__,
         {
             "vsphere.list_datacenters_via_proxy":
             MagicMock(return_value=[]),
             "vsphere.create_datacenter": mock_create_datacenter,
         },
     ):
         res = esxdatacenter.datacenter_configured("fake_dc")
     mock_create_datacenter.assert_called_once_with("fake_dc", self.mock_si)
     self.assertDictEqual(
         res,
         {
             "name": "fake_dc",
             "changes": {
                 "new": {
                     "name": "fake_dc"
                 }
             },
             "result": True,
             "comment": "Created datacenter 'fake_dc'.",
         },
     )
Esempio n. 4
0
 def test_state_raise_command_execution_error_test_mode(self):
     with patch.dict(esxdatacenter.__opts__, {'test': True}):
         with patch.dict(
                 esxdatacenter.__salt__, {
                     'vsphere.list_datacenters_via_proxy':
                     MagicMock(side_effect=CommandExecutionError('Error'))
                 }):
             res = esxdatacenter.datacenter_configured('fake_dc')
     self.assertDictEqual(res, {
         'name': 'fake_dc',
         'changes': {},
         'result': None,
         'comment': 'Error'
     })
Esempio n. 5
0
 def test_state_raise_command_execution_error_test_mode(self):
     with patch.dict(esxdatacenter.__opts__, {"test": True}):
         with patch.dict(
             esxdatacenter.__salt__,
             {
                 "vsphere.list_datacenters_via_proxy": MagicMock(
                     side_effect=CommandExecutionError("Error")
                 )
             },
         ):
             res = esxdatacenter.datacenter_configured("fake_dc")
     self.assertDictEqual(
         res, {"name": "fake_dc", "changes": {}, "result": None, "comment": "Error"}
     )
Esempio n. 6
0
 def test_dc_name_different_proxy(self):
     with patch.dict(
         esxdatacenter.__salt__,
         {"vsphere.get_proxy_type": MagicMock(return_value="different_proxy")},
     ):
         res = esxdatacenter.datacenter_configured("fake_dc")
     self.assertDictEqual(
         res,
         {
             "name": "fake_dc",
             "changes": {},
             "result": True,
             "comment": "Datacenter 'fake_dc' already "
             "exists. Nothing to be done.",
         },
     )
Esempio n. 7
0
 def test_state_raise_command_execution_error_after_si(self):
     mock_disconnect = MagicMock()
     with patch.dict(
         esxdatacenter.__salt__,
         {
             "vsphere.disconnect": mock_disconnect,
             "vsphere.list_datacenters_via_proxy": MagicMock(
                 side_effect=CommandExecutionError("Error")
             ),
         },
     ):
         res = esxdatacenter.datacenter_configured("fake_dc")
     mock_disconnect.assert_called_once_with(self.mock_si)
     self.assertDictEqual(
         res, {"name": "fake_dc", "changes": {}, "result": False, "comment": "Error"}
     )
Esempio n. 8
0
 def test_state_get_service_instance_raise_command_execution_error(self):
     mock_disconnect = MagicMock()
     with patch.dict(
         esxdatacenter.__salt__,
         {
             "vsphere.disconnect": mock_disconnect,
             "vsphere.get_service_instance_via_proxy": MagicMock(
                 side_effect=CommandExecutionError("Error")
             ),
         },
     ):
         res = esxdatacenter.datacenter_configured("fake_dc")
     self.assertEqual(mock_disconnect.call_count, 0)
     self.assertDictEqual(
         res, {"name": "fake_dc", "changes": {}, "result": False, "comment": "Error"}
     )
Esempio n. 9
0
 def test_create_datacenter_test_mode(self):
     with patch.dict(esxdatacenter.__opts__, {"test": True}):
         with patch.dict(
             esxdatacenter.__salt__,
             {"vsphere.list_datacenters_via_proxy": MagicMock(return_value=[])},
         ):
             res = esxdatacenter.datacenter_configured("fake_dc")
     self.assertDictEqual(
         res,
         {
             "name": "fake_dc",
             "changes": {"new": {"name": "fake_dc"}},
             "result": None,
             "comment": "State will create " "datacenter 'fake_dc'.",
         },
     )
Esempio n. 10
0
 def test_dc_name_different_proxy(self):
     with patch.dict(esxdatacenter.__salt__, {
             'vsphere.get_proxy_type':
             MagicMock(return_value='different_proxy')
     }):
         res = esxdatacenter.datacenter_configured('fake_dc')
     self.assertDictEqual(
         res, {
             'name':
             'fake_dc',
             'changes': {},
             'result':
             True,
             'comment':
             'Datacenter \'fake_dc\' already '
             'exists. Nothing to be done.'
         })
Esempio n. 11
0
 def test_state_raise_command_execution_error_after_si(self):
     mock_disconnect = MagicMock()
     with patch.dict(
             esxdatacenter.__salt__, {
                 'vsphere.disconnect':
                 mock_disconnect,
                 'vsphere.list_datacenters_via_proxy':
                 MagicMock(side_effect=CommandExecutionError('Error'))
             }):
         res = esxdatacenter.datacenter_configured('fake_dc')
     mock_disconnect.assert_called_once_with(self.mock_si)
     self.assertDictEqual(res, {
         'name': 'fake_dc',
         'changes': {},
         'result': False,
         'comment': 'Error'
     })
Esempio n. 12
0
 def test_state_get_service_instance_raise_command_execution_error(self):
     mock_disconnect = MagicMock()
     with patch.dict(
             esxdatacenter.__salt__, {
                 'vsphere.disconnect':
                 mock_disconnect,
                 'vsphere.get_service_instance_via_proxy':
                 MagicMock(side_effect=CommandExecutionError('Error'))
             }):
         res = esxdatacenter.datacenter_configured('fake_dc')
     self.assertEqual(mock_disconnect.call_count, 0)
     self.assertDictEqual(res, {
         'name': 'fake_dc',
         'changes': {},
         'result': False,
         'comment': 'Error'
     })
Esempio n. 13
0
 def test_create_datacenter_test_mode(self):
     with patch.dict(esxdatacenter.__opts__, {'test': True}):
         with patch.dict(esxdatacenter.__salt__, {
                 'vsphere.list_datacenters_via_proxy':
                 MagicMock(return_value=[])
         }):
             res = esxdatacenter.datacenter_configured('fake_dc')
     self.assertDictEqual(
         res, {
             'name': 'fake_dc',
             'changes': {
                 'new': {
                     'name': 'fake_dc'
                 }
             },
             'result': None,
             'comment': 'State will create '
             'datacenter \'fake_dc\'.'
         })
Esempio n. 14
0
 def test_create_datacenter(self):
     mock_create_datacenter = MagicMock()
     with patch.dict(
             esxdatacenter.__salt__, {
                 'vsphere.list_datacenters_via_proxy':
                 MagicMock(return_value=[]),
                 'vsphere.create_datacenter': mock_create_datacenter
             }):
         res = esxdatacenter.datacenter_configured('fake_dc')
     mock_create_datacenter.assert_called_once_with('fake_dc', self.mock_si)
     self.assertDictEqual(
         res, {
             'name': 'fake_dc',
             'changes': {
                 'new': {
                     'name': 'fake_dc'
                 }
             },
             'result': True,
             'comment': 'Created datacenter \'fake_dc\'.'
         })
Esempio n. 15
0
 def test_dc_name_esxdatacenter_proxy(self):
     with patch.dict(
         esxdatacenter.__salt__,
         {
             "vsphere.get_proxy_type": MagicMock(return_value="esxdatacenter"),
             "esxdatacenter.get_details": MagicMock(
                 return_value={"datacenter": "proxy_dc"}
             ),
         },
     ):
         res = esxdatacenter.datacenter_configured("fake_dc")
     self.assertDictEqual(
         res,
         {
             "name": "fake_dc",
             "changes": {},
             "result": True,
             "comment": "Datacenter 'proxy_dc' "
             "already exists. Nothing to be done.",
         },
     )