def test_create_2nic_instance(self): ctx = self.mock_ctx('testcreate2nicinstance') current_ctx.set(ctx=ctx) ctx.logger.info("BEGIN create 2 NIC VM test: {}".format(ctx.instance.id)) subnet_name = 'instancesubnet_test_2_' + self.__random_id nic_name = 'instance_nic_test_2_' + self.__random_id ctx.logger.info("create new subnet") ctx.node.properties[constants.SUBNET_KEY] = subnet_name ctx.node.properties[constants.SUBNET_ADDRESS_KEY] =\ "10.0.2.0/24" current_ctx.set(ctx=ctx) subnet.create(ctx=ctx) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "subnet",constants.SUCCEEDED, 600) ctx.logger.info("create second NIC") ctx.node.properties[constants.NETWORK_INTERFACE_KEY] = nic_name ctx.node.properties[constants.NIC_PRIMARY_KEY] = True ctx.node.properties[constants.AZURE_CONFIG_KEY][constants.SUBNET_KEY] = subnet_name for relationship in ctx.instance.relationships: if relationship.type == constants.NIC_CONNECTED_TO_SUBNET: relationship.target.instance.runtime_properties[constants.SUBNET_KEY] = subnet_name current_ctx.set(ctx=ctx) nic.create(ctx=ctx) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "nic",constants.SUCCEEDED, 600) ctx.logger.info("create VM") ctx.node.properties[constants.FLAVOR_KEY] = 'Standard_A3' ctx.instance.relationships.append(test_mockcontext.MockRelationshipContext(node_id='test', runtime_properties={ constants.NETWORK_INTERFACE_KEY: nic_name, constants.NIC_PRIMARY_KEY: True }, type=constants.INSTANCE_CONNECTED_TO_NIC) ) current_ctx.set(ctx=ctx) instance.create(ctx=ctx) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "instance",constants.SUCCEEDED, 600) ctx.logger.info("verify the NIC's number of the instance") json = instance.get_json_from_azure() self.assertEqual(len(json['properties']['networkProfile']['networkInterfaces']),2) ctx.logger.info("delete VM") self.assertEqual(202, instance.delete(ctx=ctx)) ctx.logger.info("END create VM test")
def test_delete_subnet(self): ctx = self.mock_ctx("testdeletesubnet", cdir="10.0.3.0/24") ctx.logger.info("BEGIN test_delete_subnet") current_ctx.set(ctx=ctx) status_code = subnet.create(ctx=ctx) ctx.logger.debug("status_code =" + str(status_code)) self.assertTrue(bool((status_code == 200) or (status_code == 201))) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "subnet", constants.SUCCEEDED, timeout=600) current_ctx.set(ctx=ctx) ctx.logger.info("create subnet with deletable propertie set to False") ctx.node.properties[constants.DELETABLE_KEY] = False ctx.logger.info("not delete subnet") self.assertEqual(0, subnet.delete(ctx=ctx)) current_ctx.set(ctx=ctx) ctx.logger.info("Set deletable propertie to True") ctx.node.properties[constants.DELETABLE_KEY] = True status_code = subnet.delete(ctx=ctx) ctx.logger.debug("status_code =" + str(status_code)) self.assertTrue(bool((status_code == 202) or (status_code == 204))) try: current_ctx.set(ctx=ctx) utils.wait_status(ctx, "subnet", "waiting for exception", timeout=600) except utils.WindowsAzureError: pass ctx.logger.info("END test_delete_subnet")
def setUpClass(self): ctx = self.mock_ctx('init','') ctx.logger.info("BEGIN test datadisk number "\ + self.__random_id) current_ctx.set(ctx=ctx) ctx.logger.info("CREATE ressource_group") resource_group.create(ctx=ctx) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "resource_group", constants.SUCCEEDED, timeout=600) current_ctx.set(ctx=ctx) ctx.logger.info("CREATE storage account") ctx.node.properties[constants.ACCOUNT_TYPE_KEY] = "Standard_LRS" storage.create(ctx=ctx) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "storage",constants.SUCCEEDED, timeout=600) ctx.logger.info("CREATE network") current_ctx.set(ctx=ctx) ctx.node.properties[constants.VIRTUAL_NETWORK_ADDRESS_KEY] = \ "10.0.0.0/16" network.create(ctx=ctx) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "network",constants.SUCCEEDED, timeout=600) ctx.logger.info("CREATE subnet") current_ctx.set(ctx=ctx) ctx.node.properties[constants.SUBNET_ADDRESS_KEY] = "10.0.1.0/24" ctx.instance.runtime_properties[constants.VIRTUAL_NETWORK_KEY] =\ "diskvirtualnetwork_test" + self.__random_id subnet.create(ctx=ctx) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "subnet",constants.SUCCEEDED, timeout=600) ctx.logger.info("CREATE NIC") current_ctx.set(ctx=ctx) nic.create(ctx=ctx) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "nic",constants.SUCCEEDED, timeout=600)
def test_connect_security_group_subnet(self): ctx = self.mock_ctx("testaddsecugroupsubnet", cdir="10.0.5.0/24") ctx.logger.info("BEGIN test_connect_security_group_subnet") ctx.logger.info("create security_group") self.assertEqual(201, security_group.create(ctx=ctx)) ctx.logger.debug( "security_group_id = {}".format(ctx.instance.runtime_properties[constants.SECURITY_GROUP_ID_KEY]) ) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "security_group", constants.SUCCEEDED, timeout=900) ctx.instance.relationships.append( test_mockcontext.MockRelationshipContext( node_id="test", runtime_properties={ constants.SECURITY_GROUP_ID_KEY: ctx.instance.runtime_properties[constants.SECURITY_GROUP_ID_KEY] }, type=constants.SUBNET_CONNECTED_TO_SECURITY_GROUP, ) ) current_ctx.set(ctx=ctx) status_code = subnet.create(ctx=ctx) ctx.logger.debug("status_code = " + str(status_code)) self.assertTrue(bool((status_code == 200) or (status_code == 201))) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "subnet", constants.SUCCEEDED, timeout=600) ctx.logger.info("test subnet is connected to a security_group") current_ctx.set(ctx=ctx) json = subnet.get_json_from_azure(ctx=ctx) self.assertIsNotNone(json["properties"]["networkSecurityGroup"]) self.assertEqual( str(json["properties"]["networkSecurityGroup"]["id"]).lower(), str(ctx.instance.runtime_properties[constants.SECURITY_GROUP_ID_KEY]).lower(), ) current_ctx.set(ctx=ctx) status_code = subnet.delete(ctx=ctx) ctx.logger.debug("status_code = " + str(status_code)) self.assertTrue(bool((status_code == 202) or (status_code == 204))) try: current_ctx.set(ctx=ctx) utils.wait_status(ctx, "subnet", "waiting for exception", timeout=600) except utils.WindowsAzureError: pass ctx.logger.info("delete security_group") self.assertEqual(202, security_group.delete(ctx=ctx)) ctx.logger.info("END test_connect_security_group_subnet")
def test_conflict_subnet(self): ctx = self.mock_ctx("testconflictsubnet", cdir="10.0.4.0/24") ctx.logger.info("BEGIN test_conflict_subnet") current_ctx.set(ctx=ctx) status_code = subnet.create(ctx=ctx) ctx.logger.debug("status_code =" + str(status_code)) self.assertTrue(bool((status_code == 200) or (status_code == 201))) current_ctx.set(ctx=ctx) utils.wait_status(ctx, "subnet", constants.SUCCEEDED, timeout=600) ctx.logger.info("Conflict Creating Subnet") current_ctx.set(ctx=ctx) self.assertNotEqual(201, subnet.create(ctx=ctx)) ctx.logger.info("Conflict detected") current_ctx.set(ctx=ctx) status_code = subnet.delete(ctx=ctx) ctx.logger.debug("status_code =" + str(status_code)) self.assertTrue(bool((status_code == 202) or (status_code == 204))) try: current_ctx.set(ctx=ctx) utils.wait_status(ctx, "subnet", "waiting for exception", timeout=600) except utils.WindowsAzureError: pass ctx.logger.info("Subnet Deleted") current_ctx.set(ctx=ctx) status_code = subnet.delete(ctx=ctx) ctx.logger.debug("status_code =" + str(status_code)) self.assertTrue(bool((status_code == 202) or (status_code == 204))) try: current_ctx.set(ctx=ctx) utils.wait_status(ctx, "subnet", "waiting for exception", timeout=600) except utils.WindowsAzureError: pass ctx.logger.info("Virtual subnet Deleted") ctx.logger.info("END test_conflict_subnet")
def setUpClass(self): ctx = self.mock_ctx('init') ctx.logger.info("BEGIN test NIC number " + self.__random_id) ctx.logger.info("CREATE NIC\'s required resources") ctx.logger.info("CREATE ressource_group") current_ctx.set(ctx=ctx) resource_group.create(ctx=ctx) ctx.logger.info("CREATE public_ip") current_ctx.set(ctx=ctx) ctx.node.properties[constants.PUBLIC_IP_KEY] = "nic_public_ip_test" + self.__random_id public_ip.create(ctx=ctx) ctx.logger.info("CREATE network") current_ctx.set(ctx=ctx) ctx.node.properties[constants.VIRTUAL_NETWORK_ADDRESS_KEY] = "10.0.0.0/16" network.create(ctx=ctx) ctx.logger.info("CREATE subnet") current_ctx.set(ctx=ctx) ctx.node.properties[constants.SUBNET_ADDRESS_KEY] = "10.0.1.0/24" subnet.create(ctx=ctx)