diff --git a/magnum_cluster_api/tests/conftest.py b/magnum_cluster_api/tests/conftest.py index 8dcbbf2d..9fa4047d 100644 --- a/magnum_cluster_api/tests/conftest.py +++ b/magnum_cluster_api/tests/conftest.py @@ -95,6 +95,15 @@ def mock_osc(session_mocker, image): ) ) + # Nova + def _gen_m_server_group(): + return openstack.compute.v2.server_group.ServerGroup( + id=uuidutils.generate_uuid() + ) + mock_nova_client = mock_clients.nova.return_value + sgs = [_gen_m_server_group() for i in range(1, 100)] + mock_nova_client.server_groups.create.side_effect = sgs + # Glance mock_glance_client = mock_clients.glance.return_value mock_glance_client.images.get.return_value = image @@ -273,3 +282,11 @@ def server_side_apply_matcher(): "force": "True", } ) + + +@pytest.fixture(scope="session") +def mock_cache(session_mocker): + session_mocker.patch( + "magnum_cluster_api.cache.ServerGroupCache.get", return_value=None + ) + session_mocker.patch("magnum_cluster_api.cache.ServerGroupCache.set") diff --git a/magnum_cluster_api/tests/functional/conftest.py b/magnum_cluster_api/tests/functional/conftest.py index a59a9b92..d7dccb94 100644 --- a/magnum_cluster_api/tests/functional/conftest.py +++ b/magnum_cluster_api/tests/functional/conftest.py @@ -25,6 +25,7 @@ def cluster( mock_validate_cluster, mock_osc, mock_certificates, + mock_cache, ): try: ubuntu_driver.create_cluster(context, cluster_obj, 60) diff --git a/magnum_cluster_api/tests/functional/test_driver.py b/magnum_cluster_api/tests/functional/test_driver.py index 6d9891f0..63d2fa38 100644 --- a/magnum_cluster_api/tests/functional/test_driver.py +++ b/magnum_cluster_api/tests/functional/test_driver.py @@ -29,47 +29,18 @@ def setup(self, cluster): self.api = clients.get_pykube_api() self.cluster = cluster - def _assert_machine_deployment_config_matches_node_group(self, md, node_group): - assert md is not None - # TODO: more? - @tenacity.retry( stop=tenacity.stop_after_attempt(10), wait=tenacity.wait_fixed(1), ) - def _assert_machine_deployments_for_node_groups( + def _assert_server_groups_for_node_groups( self, *node_groups: magnum_objects.NodeGroup ): - mds = objects.MachineDeployment.objects( - self.api, namespace="magnum-system" - ).filter( - selector={ - "cluster.x-k8s.io/cluster-name": self.cluster.stack_id, - }, - ) - - worker_ngs = [ng for ng in node_groups if ng.role != "master"] - - assert len(mds) == len(worker_ngs), "Expected %d MachineDeployments, got %d" % ( - len(worker_ngs), - len(mds), - ) - - # NOTE(mnaser): We need to loop over all the node groups and make sure - # that the machine deployments are created for them. - for ng in worker_ngs: - md = objects.MachineDeployment.for_node_group(self.api, self.cluster, ng) - self._assert_machine_deployment_config_matches_node_group(md, ng) - - # NOTE(mnaser): We also need to make sure there are no extra machine - # deployments created. - for md in mds: - assert md.labels["topology.cluster.x-k8s.io/deployment-name"] in [ - ng.name for ng in node_groups - ] + pass + # We need to add server group asserts here def test_default_node_group(self): - self._assert_machine_deployments_for_node_groups(*self.cluster.nodegroups) + self._assert_server_groups_for_node_groups(*self.cluster.nodegroups) def _create_node_group(self, context, driver, node_group_name, cluster_template): new_node_group = utils.get_test_nodegroup( @@ -140,7 +111,7 @@ def test_upgrade_cluster_with_multiple_node_groups( cluster_resource = objects.Cluster.for_magnum_cluster(self.api, self.cluster) assert cluster_resource.observed_generation != current_observed_generation - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, ) @@ -149,11 +120,11 @@ def test_upgrade_cluster_with_multiple_node_groups( def test_create_node_group( self, mock_validate_nodegroup, context, ubuntu_driver, cluster_template ): - self._assert_machine_deployments_for_node_groups(*self.cluster.nodegroups) + self._assert_server_groups_for_node_groups(*self.cluster.nodegroups) new_node_group = self._create_node_group( context, ubuntu_driver, "high-cpu", cluster_template ) - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, new_node_group, ) @@ -161,87 +132,87 @@ def test_create_node_group( def test_create_and_delete_node_group( self, mock_validate_nodegroup, context, ubuntu_driver, cluster_template ): - self._assert_machine_deployments_for_node_groups(*self.cluster.nodegroups) + self._assert_server_groups_for_node_groups(*self.cluster.nodegroups) new_node_group = self._create_node_group( context, ubuntu_driver, "high-cpu", cluster_template ) - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, new_node_group, ) ubuntu_driver.delete_nodegroup(context, self.cluster, new_node_group) - self._assert_machine_deployments_for_node_groups(*self.cluster.nodegroups) + self._assert_server_groups_for_node_groups(*self.cluster.nodegroups) def test_create_two_node_groups( - self, mock_validate_nodegroup, context, ubuntu_driver, cluster_template + self, mock_validate_nodegroup, mock_osc, context, ubuntu_driver, cluster_template ): - self._assert_machine_deployments_for_node_groups(*self.cluster.nodegroups) + self._assert_server_groups_for_node_groups(*self.cluster.nodegroups) first_new_node_group = self._create_node_group( context, ubuntu_driver, "high-cpu", cluster_template ) - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, first_new_node_group, ) second_new_node_group = self._create_node_group( context, ubuntu_driver, "high-memory", cluster_template ) - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, first_new_node_group, second_new_node_group, ) def test_create_and_delete_two_node_groups_deleting_newest_first( - self, mock_validate_nodegroup, context, ubuntu_driver, cluster_template + self, mock_validate_nodegroup, mock_osc, context, ubuntu_driver, cluster_template ): - self._assert_machine_deployments_for_node_groups(*self.cluster.nodegroups) + self._assert_server_groups_for_node_groups(*self.cluster.nodegroups) first_new_node_group = self._create_node_group( context, ubuntu_driver, "high-cpu", cluster_template ) - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, first_new_node_group, ) second_new_node_group = self._create_node_group( context, ubuntu_driver, "high-memory", cluster_template ) - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, first_new_node_group, second_new_node_group, ) ubuntu_driver.delete_nodegroup(context, self.cluster, second_new_node_group) - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, first_new_node_group, ) ubuntu_driver.delete_nodegroup(context, self.cluster, first_new_node_group) - self._assert_machine_deployments_for_node_groups(*self.cluster.nodegroups) + self._assert_server_groups_for_node_groups(*self.cluster.nodegroups) def test_create_and_delete_two_node_groups_deleting_oldest_first( - self, mock_validate_nodegroup, context, ubuntu_driver, cluster_template + self, mock_validate_nodegroup, mock_osc, context, ubuntu_driver, cluster_template ): - self._assert_machine_deployments_for_node_groups(*self.cluster.nodegroups) + self._assert_server_groups_for_node_groups(*self.cluster.nodegroups) first_new_node_group = self._create_node_group( context, ubuntu_driver, "high-cpu", cluster_template ) - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, first_new_node_group, ) second_new_node_group = self._create_node_group( context, ubuntu_driver, "high-memory", cluster_template ) - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, first_new_node_group, second_new_node_group, ) ubuntu_driver.delete_nodegroup(context, self.cluster, first_new_node_group) - self._assert_machine_deployments_for_node_groups( + self._assert_server_groups_for_node_groups( *self.cluster.nodegroups, second_new_node_group, ) ubuntu_driver.delete_nodegroup(context, self.cluster, second_new_node_group) - self._assert_machine_deployments_for_node_groups(*self.cluster.nodegroups) + self._assert_server_groups_for_node_groups(*self.cluster.nodegroups)