def test_update2(self, notify, mock_policy, mock_cluster, mock_cp, mock_action): mock_cluster.return_value = mock.Mock(id='12345678abcd') mock_policy.return_value = mock.Mock(id='87654321abcd') mock_action.return_value = 'ACTION_ID' mock_cp.return_value = mock.Mock() req = orco.ClusterUpdatePolicyRequest(identity='C1', policy_id='P1', enabled=False) res = self.eng.cluster_policy_update(self.ctx, req.obj_to_primitive()) self.assertEqual({'action': 'ACTION_ID'}, res) mock_cluster.assert_called_once_with(self.ctx, 'C1') mock_policy.assert_called_once_with(self.ctx, 'P1') mock_cp.assert_called_once_with(self.ctx, '12345678abcd', '87654321abcd') mock_action.assert_called_once_with( self.ctx, '12345678abcd', consts.CLUSTER_UPDATE_POLICY, name='update_policy_12345678', cause=consts.CAUSE_RPC, status=action_mod.Action.READY, inputs={ 'policy_id': '87654321abcd', 'enabled': False }, ) notify.assert_called_once_with()
def test_init(self): sot = clusters.ClusterUpdatePolicyRequest(identity='foo', policy_id='bar') self.assertEqual('foo', sot.identity) self.assertEqual('bar', sot.policy_id) self.assertFalse(sot.obj_attr_is_set('enabled')) sot.obj_set_defaults() self.assertTrue(sot.obj_attr_is_set('enabled')) self.assertTrue(sot.enabled)
def test_update2_cluster_not_found(self, mock_cluster): mock_cluster.side_effect = exc.ResourceNotFound(type='cluster', id='Bogus') req = orco.ClusterUpdatePolicyRequest(identity='Bogus', policy_id='P1', enabled=True) ex = self.assertRaises(rpc.ExpectedException, self.svc.cluster_policy_update, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceNotFound, ex.exc_info[0]) self.assertEqual("The cluster 'Bogus' could not be found.", str(ex.exc_info[1])) mock_cluster.assert_called_once_with(self.ctx, 'Bogus')
def test_update2_policy_not_found(self, mock_policy, mock_cluster): mock_cluster.return_value = mock.Mock() mock_policy.side_effect = exc.ResourceNotFound(type='policy', id='Bogus') req = orco.ClusterUpdatePolicyRequest(identity='C1', policy_id='Bogus', enabled=True) ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_policy_update, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.BadRequest, ex.exc_info[0]) self.assertEqual("The specified policy 'Bogus' could not be found.", six.text_type(ex.exc_info[1])) mock_cluster.assert_called_once_with(self.ctx, 'C1') mock_policy.assert_called_once_with(self.ctx, 'Bogus')
def test_update2_binding_not_found(self, mock_policy, mock_cluster, mock_cp): mock_cluster.return_value = mock.Mock(id='CLUSTER_ID1') mock_policy.return_value = mock.Mock(id='POLICY_ID1') mock_cp.return_value = None req = orco.ClusterUpdatePolicyRequest(identity='C1', policy_id='P1', enabled=True) ex = self.assertRaises(rpc.ExpectedException, self.svc.cluster_policy_update, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.BadRequest, ex.exc_info[0]) self.assertEqual("The policy 'P1' is not attached to the " "specified cluster 'C1'.", str(ex.exc_info[1])) mock_cluster.assert_called_once_with(self.ctx, 'C1') mock_policy.assert_called_once_with(self.ctx, 'P1') mock_cp.assert_called_once_with(self.ctx, 'CLUSTER_ID1', 'POLICY_ID1')