def test_create_nodegroup_invalid_node_count(self, mock_utcnow): ng_dict = apiutils.nodegroup_post_data(node_count=7, max_node_count=5) test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json(self.url, ng_dict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(409, response.status_int) ng_dict = apiutils.nodegroup_post_data(node_count=2, min_node_count=3) response = self.post_json(self.url, ng_dict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(409, response.status_int)
def test_create_ng_wrong_microversion(self, mock_utcnow): headers = {"Openstack-Api-Version": "container-infra 1.8"} ng_dict = apiutils.nodegroup_post_data(name="new_ng") response = self.post_json(self.url, ng_dict, headers=headers, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(406, response.status_int)
def test_create_ng_cluster_no_api_address(self): # Remove the api address from the cluster and make sure # that the request is not accepted. self.cluster.api_address = None self.cluster.save() ng_dict = apiutils.nodegroup_post_data() response = self.post_json(self.url, ng_dict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(409, response.status_int)
def test_nodegroup_init(self): nodegroup_dict = apiutils.nodegroup_post_data() del nodegroup_dict['node_count'] del nodegroup_dict['min_node_count'] del nodegroup_dict['max_node_count'] nodegroup = api_nodegroup.NodeGroup(**nodegroup_dict) self.assertEqual(1, nodegroup.node_count) self.assertEqual(1, nodegroup.min_node_count) self.assertIsNone(nodegroup.max_node_count)
def test_create_nodegroup_with_max_node_count(self, mock_utcnow): ng_dict = apiutils.nodegroup_post_data(max_node_count=5) test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json(self.url, ng_dict) self.assertEqual('application/json', response.content_type) self.assertEqual(202, response.status_int) self.assertEqual(5, response.json['max_node_count'])
def test_create_nodegroup_with_flavor(self, mock_utcnow): ng_dict = apiutils.nodegroup_post_data(flavor_id='test_flavor') test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json(self.url, ng_dict) self.assertEqual('application/json', response.content_type) self.assertEqual(202, response.status_int) self.assertEqual('test_flavor', response.json['flavor_id'])
def test_nodegroup_init(self): nodegroup_dict = apiutils.nodegroup_post_data() del nodegroup_dict['node_count'] del nodegroup_dict['min_node_count'] del nodegroup_dict['max_node_count'] nodegroup = api_nodegroup.NodeGroup(**nodegroup_dict) self.assertEqual(1, nodegroup.node_count) self.assertEqual(1, nodegroup.min_node_count) self.assertIsNone(nodegroup.max_node_count)
def test_create_nodegroup_with_labels(self, mock_utcnow): labels = {'label1': 'value1'} ng_dict = apiutils.nodegroup_post_data(labels=labels) test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json(self.url, ng_dict) self.assertEqual('application/json', response.content_type) self.assertEqual(202, response.status_int) self.assertEqual(labels, response.json['labels'])
def test_create_nodegroup(self, mock_utcnow): ng_dict = apiutils.nodegroup_post_data() test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json(self.url, ng_dict) self.assertEqual('application/json', response.content_type) self.assertEqual(202, response.status_int) self.assertTrue(uuidutils.is_uuid_like(response.json['uuid'])) self.assertFalse(response.json['is_default'])
def test_create_ng_with_merge_labels_no_labels(self): cluster_labels = {'label1': 'value1', 'label2': 'value2'} self.cluster.labels = cluster_labels self.cluster.save() ng_dict = apiutils.nodegroup_post_data(merge_labels=True) ng_dict.pop('labels') response = self.post_json(self.url, ng_dict) self.assertEqual('application/json', response.content_type) self.assertEqual(202, response.status_int) (cluster, ng), _ = self.mock_ng_create.call_args self.assertEqual(cluster.labels, ng.labels)
def test_create_nodegroup_without_node_count(self, mock_utcnow): ng_dict = apiutils.nodegroup_post_data() del ng_dict['node_count'] test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json(self.url, ng_dict) self.assertEqual('application/json', response.content_type) self.assertEqual(202, response.status_int) # Verify node_count defaults to 1 self.assertEqual(1, response.json['node_count'])
def test_create_nodegroup_with_zero_nodes(self, mock_utcnow): ng_dict = apiutils.nodegroup_post_data() ng_dict['node_count'] = 0 ng_dict['min_node_count'] = 0 test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json(self.url, ng_dict) self.assertEqual('application/json', response.content_type) self.assertEqual(202, response.status_int) # Verify node_count is set to zero self.assertEqual(0, response.json['node_count'])
def test_create_ng_same_name(self, mock_utcnow): existing_name = self.cluster.default_ng_master.name ng_dict = apiutils.nodegroup_post_data(name=existing_name) response = self.post_json(self.url, ng_dict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(409, response.status_int)
def test_create_master_ng(self, mock_utcnow): ng_dict = apiutils.nodegroup_post_data(role='master') response = self.post_json(self.url, ng_dict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int)