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): """ :return: Nothing """ 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.node_to_boot = 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') self.glance.images.upload( self.image.id, open('/tmp/trusty-server-cloudimg-amd64-disk1.img', 'rb')) # 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: 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(): if 'medium' 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.node_to_boot = 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) # check that boot returns expected results self.assertEqual(self.node_to_boot.status, 'ACTIVE', "The node not in active state!") logger.info("Using following floating ip {}".format( self.floating_ip.ip)) self.node_to_boot.add_floating_ip(self.floating_ip) self.assertTrue(common_functions.check_ip( self.nova, self.node_to_boot.id, self.floating_ip.ip))
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()
def delete_micro_flavor(os_conn): """Delete the m1.micro flavor""" flavor_id = common.get_flavor_id_by_name(os_conn.nova, "m1.micro") common.delete_flavor(os_conn.nova, flavor_id)