def tearDown(self): for inst in self.instances: common_functions.delete_instance(self.nova, inst) self.instances = [] for fip in self.floating_ips: common_functions.delete_floating_ip(self.nova, fip) self.floating_ips = [] for volume in self.volumes: self.os_conn.delete_volume(volume) self.volumes = [] for flavor in self.flavors: common_functions.delete_flavor(self.nova, flavor.id) self.flavors = [] for key in self.keys: common_functions.delete_keys(self.nova, key.name) self.keys = [] self.os_conn.delete_security_group(self.sec_group)
def tearDown(self): for inst in self.instances: common_functions.delete_instance(self.nova, inst) self.instances = [] for fip in self.floating_ips: common_functions.delete_floating_ip(self.nova, fip) self.floating_ips = [] for volume in self.volumes: common_functions.delete_volume(self.cinder, volume) self.volumes = [] for flavor in self.flavors: common_functions.delete_flavor(self.nova, flavor.id) self.flavors = [] for key in self.keys: common_functions.delete_keys(self.nova, key.name) self.keys = [] self.nova.security_groups.delete(self.sec_group)
def tearDown(self): if self.instance is not None: common_functions.delete_instance(self.nova, self.instance.id) if self.image is not None: common_functions.delete_image(self.glance, self.image.id) if self.our_own_flavor_was_created: common_functions.delete_flavor(self.nova, self.expected_flavor_id) # delete the floating ip self.nova.floating_ips.delete(self.floating_ip) # delete the security group self.nova.security_group_rules.delete(self.icmp_rule) self.nova.security_group_rules.delete(self.tcp_rule) self.nova.security_groups.delete(self.the_security_group.id) # delete security rules from the 'default' group self.nova.security_group_rules.delete(self.icmp_rule_default) self.nova.security_group_rules.delete(self.tcp_rule_default) self.assertEqual(self.amount_of_images_before, len(list(self.glance.images.list())), "Length of list with images should be the same")
def setUp(self): super(self.__class__, self).setUp() # Get path on node to 'images' dir self.image_name = os.path.join(settings.TEST_IMAGE_PATH, settings.WIN_SERVER_QCOW2) self.uid_list = [] # timeouts (in minutes) self.ping_timeout = 3 self.hypervisor_timeout = 10 self.amount_of_images_before = len(list(self.glance.images.list())) self.image = None self.our_own_flavor_was_created = False self.expected_flavor_id = 3 self.instance = None self.security_group_name = "ms_compatibility" # protect for multiple definition of the same group for sg in self.nova.security_groups.list(): if sg.name == self.security_group_name: self.nova.security_groups.delete(sg) # adding required security group self.the_security_group = self.nova.security_groups.create( name=self.security_group_name, description="Windows Compatibility" ) # Add rules for ICMP, TCP/22 self.icmp_rule = self.nova.security_group_rules.create( self.the_security_group.id, ip_protocol="icmp", from_port=-1, to_port=-1, cidr="0.0.0.0/0" ) self.tcp_rule = self.nova.security_group_rules.create( self.the_security_group.id, ip_protocol="tcp", from_port=22, to_port=22, cidr="0.0.0.0/0" ) # Add both rules to default group self.default_security_group_id = 0 for sg in self.nova.security_groups.list(): if sg.name == "default": self.default_security_group_id = sg.id break self.icmp_rule_default = self.nova.security_group_rules.create( self.default_security_group_id, ip_protocol="icmp", from_port=-1, to_port=-1, cidr="0.0.0.0/0" ) self.tcp_rule_default = self.nova.security_group_rules.create( self.default_security_group_id, ip_protocol="tcp", from_port=22, to_port=22, cidr="0.0.0.0/0" ) # adding floating ip self.floating_ip = self.nova.floating_ips.create(self.nova.floating_ip_pools.list()[0].name) # creating of the image self.image = self.glance.images.create(name="MyTestSystem", disk_format="qcow2", container_format="bare") with open(self.image_name, "rb") as win_image_file: self.glance.images.upload(self.image.id, win_image_file) # check that required image in active state is_activated = False while not is_activated: for image_object in self.glance.images.list(): if image_object.id == self.image.id: self.image = image_object logger.info("Image in the {} state".format(self.image.status)) if self.image.status == "active": is_activated = True break time.sleep(1) # Default - the first network_id = self.nova.networks.list()[0].id # More detailed check of network list for network in self.nova.networks.list(): if "internal" in network.label: network_id = network.id logger.info("Starting with network interface id {}".format(network_id)) # TODO(mlaptev) add check flavor parameters vs. vm parameters # Collect information about the medium flavor and create a copy of it for flavor in self.nova.flavors.list(): # TODO(rpromyshlennikov): change flavor to medium if we will have # memory issues on windows and CI will be ready for it if "small" in flavor.name and "copy.of." not in flavor.name: new_flavor_name = "copy.of." + flavor.name new_flavor_id = common_functions.get_flavor_id_by_name(self.nova, new_flavor_name) # delete the flavor if it already exists if new_flavor_id is not None: common_functions.delete_flavor(self.nova, new_flavor_id) # create the flavor for our needs expected_flavor = self.nova.flavors.create( name=new_flavor_name, ram=flavor.ram, vcpus=1, disk=flavor.disk # Only one VCPU ) self.expected_flavor_id = expected_flavor.id self.our_own_flavor_was_created = True break logger.info("Starting with flavor {}".format(self.nova.flavors.get(self.expected_flavor_id))) # nova boot self.instance = common_functions.create_instance( nova_client=self.nova, inst_name="MyTestSystemWithNova", flavor_id=self.expected_flavor_id, net_id=network_id, security_groups=[self.the_security_group.name, "default"], image_id=self.image.id, ) logger.info("Using following floating ip {}".format(self.floating_ip.ip)) self.instance.add_floating_ip(self.floating_ip) self.assertTrue(common_functions.check_ip(self.nova, self.instance.id, self.floating_ip.ip)) self.wait_instance_to_boot()
def setUp(self): super(self.__class__, self).setUp() # Get path on node to 'images' dir self.image_name = os.path.join(settings.TEST_IMAGE_PATH, settings.WIN_SERVER_QCOW2) self.uid_list = [] # timeouts (in minutes) self.ping_timeout = 3 self.hypervisor_timeout = 10 self.amount_of_images_before = len(list(self.glance.images.list())) self.image = None self.our_own_flavor_was_created = False self.expected_flavor_id = 3 self.instance = None self.security_group_name = "ms_compatibility" # protect for multiple definition of the same group for sg in self.nova.security_groups.list(): if sg.name == self.security_group_name: self.nova.security_groups.delete(sg) # adding required security group self.the_security_group = self.nova.security_groups.create( name=self.security_group_name, description="Windows Compatibility") # Add rules for ICMP, TCP/22 self.icmp_rule = self.nova.security_group_rules.create( self.the_security_group.id, ip_protocol="icmp", from_port=-1, to_port=-1, cidr="0.0.0.0/0") self.tcp_rule = self.nova.security_group_rules.create( self.the_security_group.id, ip_protocol="tcp", from_port=22, to_port=22, cidr="0.0.0.0/0") # Add both rules to default group self.default_security_group_id = 0 for sg in self.nova.security_groups.list(): if sg.name == 'default': self.default_security_group_id = sg.id break self.icmp_rule_default = self.nova.security_group_rules.create( self.default_security_group_id, ip_protocol="icmp", from_port=-1, to_port=-1, cidr="0.0.0.0/0") self.tcp_rule_default = self.nova.security_group_rules.create( self.default_security_group_id, ip_protocol="tcp", from_port=22, to_port=22, cidr="0.0.0.0/0") # adding floating ip self.floating_ip = self.nova.floating_ips.create( self.nova.floating_ip_pools.list()[0].name) # creating of the image self.image = self.glance.images.create( name='MyTestSystem', disk_format='qcow2', container_format='bare') with open(self.image_name, 'rb') as win_image_file: self.glance.images.upload( self.image.id, win_image_file) # check that required image in active state is_activated = False while not is_activated: for image_object in self.glance.images.list(): if image_object.id == self.image.id: self.image = image_object logger.info( "Image in the {} state".format(self.image.status)) if self.image.status == 'active': is_activated = True break time.sleep(1) # Default - the first network_id = self.nova.networks.list()[0].id # More detailed check of network list for network in self.nova.networks.list(): if 'internal' in network.label: network_id = network.id logger.info("Starting with network interface id {}".format(network_id)) # TODO(mlaptev) add check flavor parameters vs. vm parameters # Collect information about the medium flavor and create a copy of it for flavor in self.nova.flavors.list(): # TODO(rpromyshlennikov): change flavor to medium if we will have # memory issues on windows and CI will be ready for it if 'small' in flavor.name and 'copy.of.' not in flavor.name: new_flavor_name = "copy.of." + flavor.name new_flavor_id = common_functions.get_flavor_id_by_name( self.nova, new_flavor_name) # delete the flavor if it already exists if new_flavor_id is not None: common_functions.delete_flavor(self.nova, new_flavor_id) # create the flavor for our needs expected_flavor = self.nova.flavors.create( name=new_flavor_name, ram=flavor.ram, vcpus=1, # Only one VCPU disk=flavor.disk) self.expected_flavor_id = expected_flavor.id self.our_own_flavor_was_created = True break logger.info("Starting with flavor {}".format( self.nova.flavors.get(self.expected_flavor_id))) # nova boot self.instance = common_functions.create_instance( nova_client=self.nova, inst_name="MyTestSystemWithNova", flavor_id=self.expected_flavor_id, net_id=network_id, security_groups=[self.the_security_group.name, 'default'], image_id=self.image.id) logger.info("Using following floating ip {}".format( self.floating_ip.ip)) self.instance.add_floating_ip(self.floating_ip) self.assertTrue(common_functions.check_ip(self.nova, self.instance.id, self.floating_ip.ip)) self.wait_instance_to_boot()