def test_attach2(self, notify, mock_policy, mock_cluster, mock_action): mock_cluster.return_value = mock.Mock(id='12345678abcd') mock_policy.return_value = mock.Mock(id='87654321abcd') mock_action.return_value = 'ACTION_ID' req = orco.ClusterAttachPolicyRequest(identity='C1', policy_id='P1', enabled=True) res = self.eng.cluster_policy_attach(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_action.assert_called_once_with( self.ctx, '12345678abcd', consts.CLUSTER_ATTACH_POLICY, name='attach_policy_12345678', cause=consts.CAUSE_RPC, status=action_mod.Action.READY, inputs={ 'policy_id': '87654321abcd', 'enabled': True }, ) notify.assert_called_once_with()
def test_init(self): sot = clusters.ClusterAttachPolicyRequest(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_attach2_cluster_not_found(self, mock_cluster): mock_cluster.side_effect = exc.ResourceNotFound(type='cluster', id='BOGUS') req = orco.ClusterAttachPolicyRequest(identity='BOGUS', policy_id='POLICY_ID') ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_policy_attach, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceNotFound, ex.exc_info[0]) self.assertEqual("The cluster 'BOGUS' could not be found.", six.text_type(ex.exc_info[1])) mock_cluster.assert_called_once_with(self.ctx, 'BOGUS')
def test_attach2_policy_not_found(self, mock_policy, mock_cluster): mock_cluster.return_value = mock.Mock(id='12345678abcd') mock_policy.side_effect = exc.ResourceNotFound(type='policy', id='BOGUS') req = orco.ClusterAttachPolicyRequest(identity='CLUSTER', policy_id='BOGUS') ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_policy_attach, 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, 'CLUSTER') mock_policy.assert_called_once_with(self.ctx, 'BOGUS')