def test_vcn_stack_update_base_vcn(self): # Create detault ie and subnets vcn_stack = new_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=self.options["vcn"], internet_gateway_kwargs=self.options["internetgateway"], route_table_kwargs=self.options["routetable"], ) self.assertTrue(valid_vcn_stack(vcn_stack)) subnet_id, subnet = vcn_stack["subnets"].popitem() # Apply updates to the subnets subnet_options = {} subnet_options["display_name"] = self.options["subnet"]["display_name"] subnet_options["id"] = subnet_id required_subnets = [subnet_options] self.assertFalse( valid_vcn_stack(vcn_stack, required_subnets=required_subnets)) updated_vcn_stack = update_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=self.options["vcn"], internet_gateway_kwargs=self.options["internetgateway"], route_table_kwargs=self.options["routetable"], subnet_kwargs=subnet_options, ) self.assertTrue(valid_vcn_stack(updated_vcn_stack)) self.assertTrue( valid_vcn_stack(updated_vcn_stack, required_subnets=required_subnets))
def test_vcn_refresh_stack(self): # Extract the ip of the instance self.vcn_stack = new_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=self.options["vcn"], internet_gateway_kwargs=self.options["internetgateway"], route_table_kwargs=self.options["routetable"], subnet_kwargs=self.options["subnet"], ) self.assertTrue(valid_vcn_stack(self.vcn_stack)) vcn_id_stack = {"id": self.vcn_stack["id"]} refreshed_vcn = refresh_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=vcn_id_stack, ) self.assertTrue(valid_vcn_stack(refreshed_vcn)) self.assertTrue(equal_vcn_stack(self.vcn_stack, refreshed_vcn)) vcn_name_stack = {"display_name": self.vcn_stack["vcn"].display_name} refreshed_vcn = refresh_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=vcn_name_stack, ) self.assertTrue(valid_vcn_stack(refreshed_vcn)) self.assertTrue(equal_vcn_stack(self.vcn_stack, refreshed_vcn))
def test_vcn_delete_stack(self): # Extract the ip of the instance self.vcn_stack = new_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=self.options["vcn"], internet_gateway_kwargs=self.options["internetgateway"], route_table_kwargs=self.options["routetable"], subnet_kwargs=self.options["subnet"], ) self.assertTrue(valid_vcn_stack(self.vcn_stack)) created_vcn_stack = get_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], self.vcn_stack["id"], ) self.assertTrue(valid_vcn_stack(created_vcn_stack)) self.assertTrue(equal_vcn_stack(self.vcn_stack, created_vcn_stack)) deleted_stack = delete_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], self.vcn_stack["id"], ) self.assertTrue(stack_was_deleted(deleted_stack))
def _new_vcn_stack(self): stack = new_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], internet_gateway_kwargs=self.options["internetgateway"], vcn_kwargs=self.options["vcn"], route_table_kwargs=self.options["routetable"], subnet_kwargs=self.options["subnet"], ) return stack
def test_vcn_stack_update_ig(self): self.vcn_stack = new_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=self.options["vcn"], internet_gateway_kwargs=self.options["internetgateway"], route_table_kwargs=self.options["routetable"], subnet_kwargs=self.options["subnet"], ) self.assertTrue(valid_vcn_stack(self.vcn_stack)) # Created the default internet gateway self.assertEqual(len(self.vcn_stack["internet_gateways"]), 1) default_ig_id, default_ig = self.vcn_stack[ "internet_gateways"].popitem() vcn_kwargs = {"id": self.vcn_stack["id"]} # Update the VCN Internet Gateway display_name and disable it new_gateway_kwargs = { "id": default_ig_id, "display_name": "New Gateway Name", "is_enabled": False, } updated_stack = update_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=vcn_kwargs, internet_gateway_kwargs=new_gateway_kwargs, ) self.assertEqual(len(updated_stack["internet_gateways"]), 1) self.assertIn(default_ig_id, updated_stack["internet_gateways"]) updated_ig = updated_stack["internet_gateways"][default_ig_id] self.assertEqual(updated_ig.display_name, new_gateway_kwargs["display_name"]) self.assertEqual(updated_ig.is_enabled, new_gateway_kwargs["is_enabled"]) deleted_stack = delete_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], self.vcn_stack["id"], ) self.assertTrue(stack_was_deleted(deleted_stack))
def test_vcn_stack_ensure(self): # Create detault ie and subnets vcn_stack = new_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=self.options["vcn"], internet_gateway_kwargs=self.options["internetgateway"], route_table_kwargs=self.options["routetable"], ) self.assertTrue(valid_vcn_stack(vcn_stack)) subnet_kwargs = dict( cidr_block="10.0.20.0/24", display_name="Ensure Subnet", dns_label="workers2", ) # Get the created Internet Gateway id ensured = ensure_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=self.options["vcn"], internet_gateway_kwargs=self.options["internetgateway"], route_table_kwargs=self.options["routetable"], subnet_kwargs=subnet_kwargs, ) self.assertTrue(ensured) refreshed_vcn_stack = refresh_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=self.options["vcn"], ) new_subnet = get_subnet_in_vcn_stack( refreshed_vcn_stack, subnet_kwargs=subnet_kwargs, optional_value_kwargs=["id", "display_name"], ) self.assertEqual(new_subnet.cidr_block, subnet_kwargs["cidr_block"]) self.assertEqual(new_subnet.display_name, subnet_kwargs["display_name"]) self.assertEqual(new_subnet.dns_label, subnet_kwargs["dns_label"])
def test_vcn_stack(self): # Extract the ip of the instance self.vcn_stack = new_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=self.options["vcn"], internet_gateway_kwargs=self.options["internetgateway"], route_table_kwargs=self.options["routetable"], subnet_kwargs=self.options["subnet"], ) self.assertTrue(valid_vcn_stack(self.vcn_stack)) _vcn_stack = get_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], self.vcn_stack["id"], ) self.assertTrue(valid_vcn_stack(_vcn_stack)) self.assertEqual(self.vcn_stack["id"], _vcn_stack["id"]) self.assertEqual(self.vcn_stack["vcn"], _vcn_stack["vcn"]) self.assertDictEqual(self.vcn_stack["internet_gateways"], _vcn_stack["internet_gateways"]) self.assertDictEqual(self.vcn_stack["subnets"], _vcn_stack["subnets"]) new_vcn_id = get(self.network_client, "get_vcn", self.vcn_stack["id"]) self.assertEqual(self.vcn_stack["id"], new_vcn_id.id) self.assertEqual(self.vcn_stack["vcn"], new_vcn_id) # Custom equal check self.assertTrue(equal_vcn_stack(self.vcn_stack, _vcn_stack)) new_vcn_name = get_vcn_by_name( self.network_client, self.options["profile"]["compartment_id"], self.options["vcn"]["display_name"], ) self.assertEqual(self.vcn_stack["id"], new_vcn_name.id) self.assertEqual(self.vcn_stack["vcn"], new_vcn_name)
dns_label="xnovotech", ) subnet_options = dict(cidr_block="10.0.1.0/24", display_name="workers", dns_label="workers") options = dict( profile=oci_profile_options, vcn=vcn_options, subnet=subnet_options, ) return options if __name__ == "__main__": options = prepare_options() network_client = new_client( VirtualNetworkClient, composite_class=VirtualNetworkClientCompositeOperations, name=options["oci"]["name"], ) stack = new_vcn_stack( network_client, options["oci"]["compartment_id"], vcn_kwargs=options["vcn"], subnet_kwargs=options["subnet"], )
def test_cluster_stack(self): # Need vcn stack for the cluster stack self.vcn_stack = new_vcn_stack( self.network_client, self.options["profile"]["compartment_id"], vcn_kwargs=self.options["vcn"], internet_gateway_kwargs=self.options["internetgateway"], route_table_kwargs=self.options["routetable"], subnet_kwargs=self.options["subnet"], ) self.assertTrue(valid_vcn_stack(self.vcn_stack)) # Available images available_images = list_entities( self.compute_client, "list_images", self.options["profile"]["compartment_id"], **self.options["cluster"]["node"]["image"]) if not available_images: raise ValueError( "No valid image could be found with options: {}".format( self.options["cluster"]["node"]["image"])) if len(available_images) > 1: raise ValueError( "More than 1 image was found with options: {}".format( self.options["cluster"]["node"]["image"])) image = available_images[0] # Prepare cluster details cluster_details = gen_cluster_stack_details(self.vcn_stack["id"], self.vcn_stack["subnets"], image, **self.options) self.cluster_stack = new_cluster_stack( self.container_engine_client, cluster_details["create_cluster"], cluster_details["create_node_pool"], ) self.assertTrue(valid_cluster_stack(self.cluster_stack)) _cluster_stack = get_cluster_stack( self.container_engine_client, self.options["profile"]["compartment_id"], self.cluster_stack["id"], ) self.assertTrue(valid_cluster_stack(_cluster_stack)) self.assertEqual(self.cluster_stack["id"], _cluster_stack["id"]) self.assertEqual(self.cluster_stack["cluster"], _cluster_stack["cluster"]) self.assertListEqual(self.cluster_stack["node_pools"], _cluster_stack["node_pools"]) new_cluster_id = get(self.container_engine_client, "get_cluster", self.cluster_stack["id"]) new_cluster_name = get_cluster_by_name( self.container_engine_client, self.options["profile"]["compartment_id"], self.cluster_stack["cluster"].name, ) self.assertEqual(self.cluster_stack["id"], new_cluster_id.id) self.assertEqual(self.cluster_stack["cluster"], new_cluster_name)