def test_request_to_primitive(self): body = clusters.ClusterCreateRequestBody(**self.body) request = {'cluster': body} sot = clusters.ClusterCreateRequest(**request) self.assertIsInstance(sot.cluster, clusters.ClusterCreateRequestBody) self.assertEqual('test-cluster', sot.cluster.name) self.assertEqual('test-profile', sot.cluster.profile_id) res = sot.obj_to_primitive() self.assertEqual(['cluster'], res['senlin_object.changes']) self.assertEqual('ClusterCreateRequest', res['senlin_object.name']) self.assertEqual('senlin', res['senlin_object.namespace']) self.assertEqual('1.0', res['senlin_object.version']) data = res['senlin_object.data']['cluster'] self.assertIn('profile_id', data['senlin_object.changes']) self.assertIn('name', data['senlin_object.changes']) self.assertEqual('ClusterCreateRequestBody', data['senlin_object.name']) self.assertEqual('senlin', data['senlin_object.namespace']) self.assertEqual('1.0', data['senlin_object.version']) self.assertEqual( { 'name': u'test-cluster', 'profile_id': u'test-profile' }, data['senlin_object.data'])
def test_request_body_to_primitive(self): sot = clusters.ClusterCreateRequestBody(**self.body) res = sot.obj_to_primitive() self.assertEqual( { 'name': u'test-cluster', 'profile_id': u'test-profile' }, res['senlin_object.data']) self.assertEqual('ClusterCreateRequestBody', res['senlin_object.name']) self.assertEqual('senlin', res['senlin_object.namespace']) self.assertEqual('1.0', res['senlin_object.version']) self.assertIn('profile_id', res['senlin_object.changes']) self.assertIn('name', res['senlin_object.changes'])
def test_cluster_create_request_body_full(self): body = copy.deepcopy(self.body) body['min_size'] = 1 body['max_size'] = 10 body['desired_capacity'] = 4 body['metadata'] = {'foo': 'bar'} body['timeout'] = 121 sot = clusters.ClusterCreateRequestBody(**body) self.assertEqual('test-cluster', sot.name) self.assertEqual('test-profile', sot.profile_id) self.assertEqual(1, sot.min_size) self.assertEqual(10, sot.max_size) self.assertEqual(4, sot.desired_capacity) self.assertEqual({'foo': 'bar'}, sot.metadata) self.assertEqual(121, sot.timeout)
def test_cluster_create_request_body(self): sot = clusters.ClusterCreateRequestBody(**self.body) self.assertEqual('test-cluster', sot.name) self.assertEqual('test-profile', sot.profile_id) self.assertFalse(sot.obj_attr_is_set('min_size')) self.assertFalse(sot.obj_attr_is_set('timeout')) sot.obj_set_defaults() self.assertTrue(sot.obj_attr_is_set('min_size')) self.assertEqual(consts.CLUSTER_DEFAULT_MIN_SIZE, sot.min_size) self.assertEqual(consts.CLUSTER_DEFAULT_MAX_SIZE, sot.max_size) self.assertEqual({}, sot.metadata) self.assertEqual(CONF.default_action_timeout, sot.timeout)