summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiexiang Yue <yueliexiang@chinamobile.com>2019-03-21 11:40:49 +0800
committerLiexiang Yue <yueliexiang@chinamobile.com>2019-03-21 11:40:49 +0800
commit9ac3a7a4882bf8d0a0814d8cff9b4abd62a74a9f (patch)
tree0a24d6e2159aa443907d06dd7680b781cdc40ed1
parent54cb529d8452c1f235fc69ea4a647e2374d475d2 (diff)
Add unit_test for Multi-Cloud Fcaps enhancement
Issue-ID: MULTICLOUD-495 Change-Id: I321823f894bba014f39455487687a0f77ff4234d Signed-off-by: Liexiang Yue <yueliexiang@chinamobile.com>
-rw-r--r--fcaps/fcaps/vesagent/tests/tests_pm_vm.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/fcaps/fcaps/vesagent/tests/tests_pm_vm.py b/fcaps/fcaps/vesagent/tests/tests_pm_vm.py
index 50db3c38..f40bd316 100644
--- a/fcaps/fcaps/vesagent/tests/tests_pm_vm.py
+++ b/fcaps/fcaps/vesagent/tests/tests_pm_vm.py
@@ -136,3 +136,93 @@ class PmVMTest(unittest.TestCase):
def test_get_epoch_now_usecond(self):
epoch = pm_vm.get_epoch_now_usecond()
self.assertGreater(epoch, 1)
+
+ @mock.patch.object(restcall, '_call_req')
+ def test_buildBacklog_pm_vm(self, mock_call_req):
+ mock_call_req.side_effect = [
+ (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"),
+ (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body")
+ ]
+ backlog = pm_vm.buildBacklog_pm_vm(
+ vimid="fcaps-hudson-dc_RegionOne",
+ backlog_input=MOCK_BACKLOG_INPUT)
+
+ self.assertIsNotNone(backlog)
+
+ @mock.patch.object(restcall, '_call_req')
+ def test_buildBacklog_pm_vm_wo_tenant_id(self, mock_call_req):
+ mock_call_req.side_effect = [
+ (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"),
+ (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body")
+ ]
+ backlog = pm_vm.buildBacklog_pm_vm(
+ vimid="fcaps-hudson-dc_RegionOne",
+ backlog_input=MOCK_BACKLOG_INPUT_wo_tenant_id)
+ self.assertIsNotNone(backlog)
+
+ @mock.patch.object(restcall, '_call_req')
+ def test_buildBacklog_pm_vm_wo_tenant(self, mock_call_req):
+ mock_call_req.side_effect = [
+ (1, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body: failed"),
+ (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body")
+ ]
+ backlog = pm_vm.buildBacklog_pm_vm(
+ vimid="fcaps-hudson-dc_RegionOne",
+ backlog_input=MOCK_BACKLOG_INPUT_wo_tenant)
+ self.assertIsNone(backlog)
+
+ @mock.patch.object(restcall, '_call_req')
+ def test_buildBacklog_pm_vm_wo_server_id(self, mock_call_req):
+ mock_call_req.side_effect = [
+ (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"),
+ (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body")
+ ]
+ backlog = pm_vm.buildBacklog_pm_vm(
+ vimid="fcaps-hudson-dc_RegionOne",
+ backlog_input=MOCK_BACKLOG_INPUT_wo_server_id)
+ self.assertIsNotNone(backlog)
+
+ @mock.patch.object(restcall, '_call_req')
+ def test_buildBacklog_pm_vm_wo_server(self, mock_call_req):
+ mock_call_req.side_effect = [
+ (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"),
+ (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body")
+ ]
+ backlog = pm_vm.buildBacklog_pm_vm(
+ vimid="fcaps-hudson-dc_RegionOne",
+ backlog_input=MOCK_BACKLOG_INPUT_wo_server)
+ self.assertIsNotNone(backlog)
+
+ @mock.patch.object(vespublish, 'publishAnyEventToVES')
+ @mock.patch.object(restcall, '_call_req')
+ def test_processBacklog_pm_vm(
+ self, mock_call_req, mock_publishAnyEventToVES):
+ mock_call_req.side_effect = [
+ (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"),
+ (0, json.dumps(MOCK_SERVER_GET_RESPONSE), "MOCKED response body")
+ ]
+ mock_publishAnyEventToVES.return_value = "mocked return value"
+
+ result = pm_vm.processBacklog_pm_vm(
+ vesAgentConfig=MOCK_vesAgentConfig,
+ vesAgentState=MOCK_vesAgentState,
+ oneBacklog=MOCK_oneBacklog)
+ self.assertIsNone(result)
+ pass
+
+ @mock.patch.object(vespublish, 'publishAnyEventToVES')
+ @mock.patch.object(restcall, '_call_req')
+ def test_processBacklog_pm_vm_wo_server(
+ self, mock_call_req, mock_publishAnyEventToVES):
+ mock_call_req.side_effect = [
+ (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"),
+ (0, json.dumps(MOCK_SERVER_GET_RESPONSE_empty), "MOCKED response body")
+ ]
+ mock_publishAnyEventToVES.return_value = "mocked return value"
+
+ result = pm_vm.processBacklog_pm_vm(
+ vesAgentConfig=MOCK_vesAgentConfig,
+ vesAgentState=MOCK_vesAgentState,
+ oneBacklog=MOCK_oneBacklog)
+
+ self.assertIsNone(result)