def test_register_get_deregister_ami_image(self):
     # Register and deregister ami image
     image = {"name": rand_name("ami-name-"),
              "location": self.bucket_name + "/" + self.ami_manifest,
              "type": "ami"}
     image["image_id"] = self.images_client.register_image(
                         name=image["name"],
                         image_location=image["location"])
     #Note(afazekas): delete_snapshot=True might trigger boto lib? bug
     image["cleanUp"] = self.addResourceCleanUp(
                             self.images_client.deregister_image,
                             image["image_id"])
     self.assertEqual(image["image_id"][0:3], image["type"])
     retrieved_image = self.images_client.get_image(image["image_id"])
     self.assertTrue(retrieved_image.name == image["name"])
     self.assertTrue(retrieved_image.id == image["image_id"])
     state = retrieved_image.state
     if state != "available":
         def _state():
             retr = self.images_client.get_image(image["image_id"])
             return retr.state
         state = state_wait(_state, "available")
     self.assertEqual("available", state)
     self.images_client.deregister_image(image["image_id"])
     #TODO(afazekas): double deregister ?
     self.cancelResourceCleanUp(image["cleanUp"])
Exemplo n.º 2
0
 def state_wait_gone(self, lfunction, final_set, valid_set):
     if not isinstance(final_set, set):
         final_set = set((final_set,))
     final_set |= self.gone_set
     state = state_wait(lfunction, final_set, valid_set)
     self.assertIn(state, valid_set | self.gone_set)
     return state
Exemplo n.º 3
0
 def test_register_get_deregister_ami_image(self):
     # Register and deregister ami image
     image = {"name": rand_name("ami-name-"),
              "location": self.bucket_name + "/" + self.ami_manifest,
              "type": "ami"}
     image["image_id"] = self.images_client.register_image(
                         name=image["name"],
                         image_location=image["location"])
     #Note(afazekas): delete_snapshot=True might trigger boto lib? bug
     image["cleanUp"] = self.addResourceCleanUp(
                             self.images_client.deregister_image,
                             image["image_id"])
     self.assertEqual(image["image_id"][0:3], image["type"])
     retrieved_image = self.images_client.get_image(image["image_id"])
     self.assertTrue(retrieved_image.name == image["name"])
     self.assertTrue(retrieved_image.id == image["image_id"])
     if retrieved_image.state != "available":
         def _state():
             retr = self.images_client.get_image(image["image_id"])
             return retr.state
         state = state_wait(_state, "available")
     self.assertEqual("available", state)
     self.images_client.deregister_image(image["image_id"])
     #TODO(afazekas): double deregister ?
     self.cancelResourceCleanUp(image["cleanUp"])
Exemplo n.º 4
0
 def state_wait_gone(self, lfunction, final_set, valid_set):
     if not isinstance(final_set, set):
         final_set = set((final_set, ))
     final_set |= self.gone_set
     lfunction = self.get_lfunction_gone(lfunction)
     state = state_wait(lfunction, final_set, valid_set)
     self.assertIn(state, valid_set | self.gone_set)
     return state
Exemplo n.º 5
0
    def setUpClass(cls):
        super(InstanceRunTest, cls).setUpClass()
        if not cls.conclusion['A_I_IMAGES_READY']:
            raise cls.skipException("".join(
                ("EC2 ", cls.__name__, ": requires ami/aki/ari manifest")))
        cls.os = clients.Manager()
        cls.s3_client = cls.os.s3_client
        cls.ec2_client = cls.os.ec2api_client
        cls.zone = cls.ec2_client.get_good_zone()
        config = cls.config
        cls.materials_path = config.boto.s3_materials_path
        ami_manifest = config.boto.ami_manifest
        aki_manifest = config.boto.aki_manifest
        ari_manifest = config.boto.ari_manifest
        cls.instance_type = config.boto.instance_type
        cls.bucket_name = rand_name("s3bucket-")
        cls.keypair_name = rand_name("keypair-")
        cls.keypair = cls.ec2_client.create_key_pair(cls.keypair_name)
        cls.addResourceCleanUp(cls.ec2_client.delete_key_pair,
                               cls.keypair_name)
        bucket = cls.s3_client.create_bucket(cls.bucket_name)
        cls.addResourceCleanUp(cls.destroy_bucket,
                               cls.s3_client.connection_data, cls.bucket_name)
        s3_upload_dir(bucket, cls.materials_path)
        cls.images = {
            "ami": {
                "name": rand_name("ami-name-"),
                "location": cls.bucket_name + "/" + ami_manifest
            },
            "aki": {
                "name": rand_name("aki-name-"),
                "location": cls.bucket_name + "/" + aki_manifest
            },
            "ari": {
                "name": rand_name("ari-name-"),
                "location": cls.bucket_name + "/" + ari_manifest
            }
        }
        for image in cls.images.itervalues():
            image["image_id"] = cls.ec2_client.register_image(
                name=image["name"], image_location=image["location"])
            cls.addResourceCleanUp(cls.ec2_client.deregister_image,
                                   image["image_id"])

        for image in cls.images.itervalues():

            def _state():
                retr = cls.ec2_client.get_image(image["image_id"])
                return retr.state

            state = state_wait(_state, "available")
            if state != "available":
                for _image in cls.images.itervalues():
                    cls.ec2_client.deregister_image(_image["image_id"])
                raise exceptions.EC2RegisterImageException(
                    image_id=image["image_id"])
Exemplo n.º 6
0
    def assertAddressReleasedWait(self, address):
        def _address_delete():
            #NOTE(afazekas): the filter gives back IP
            # even if it is not associated to my tenant
            if (address.public_ip
                    not in map(lambda a: a.public_ip,
                               self.ec2_client.get_all_addresses())):
                return "DELETED"
            return "NOTDELETED"

        state = state_wait(_address_delete, "DELETED")
        self.assertEqual(state, "DELETED")
Exemplo n.º 7
0
    def assertAddressReleasedWait(self, address):

        def _address_delete():
            #NOTE(afazekas): the filter gives back IP
            # even if it is not associated to my tenant
            if (address.public_ip not in map(lambda a: a.public_ip,
                self.ec2_client.get_all_addresses())):
                    return "DELETED"
            return "NOTDELETED"

        state = state_wait(_address_delete, "DELETED")
        self.assertEqual(state, "DELETED")
    def setUpClass(cls):
        super(InstanceRunTest, cls).setUpClass()
        if not tempest.tests.boto.A_I_IMAGES_READY:
            raise nose.SkipTest("".join(("EC2 ", cls.__name__,
                                ": requires ami/aki/ari manifest")))
        cls.os = clients.Manager()
        cls.s3_client = cls.os.s3_client
        cls.ec2_client = cls.os.ec2api_client
        config = cls.os.config
        cls.zone = cls.ec2_client.get_good_zone()
        cls.materials_path = config.boto.s3_materials_path
        ami_manifest = config.boto.ami_manifest
        aki_manifest = config.boto.aki_manifest
        ari_manifest = config.boto.ari_manifest
        cls.instance_type = config.boto.instance_type
        cls.bucket_name = rand_name("s3bucket-")
        cls.keypair_name = rand_name("keypair-")
        cls.keypair = cls.ec2_client.create_key_pair(cls.keypair_name)
        cls.addResourceCleanUp(cls.ec2_client.delete_key_pair,
                               cls.keypair_name)
        bucket = cls.s3_client.create_bucket(cls.bucket_name)
        cls.addResourceCleanUp(cls.destroy_bucket,
                               cls.s3_client.connection_data,
                               cls.bucket_name)
        s3_upload_dir(bucket, cls.materials_path)
        cls.images = {"ami":
                      {"name": rand_name("ami-name-"),
                       "location": cls.bucket_name + "/" + ami_manifest},
                      "aki":
                      {"name": rand_name("aki-name-"),
                       "location": cls.bucket_name + "/" + aki_manifest},
                      "ari":
                      {"name": rand_name("ari-name-"),
                       "location": cls.bucket_name + "/" + ari_manifest}}
        for image in cls.images.itervalues():
            image["image_id"] = cls.ec2_client.register_image(
                                name=image["name"],
                                image_location=image["location"])
            cls.addResourceCleanUp(cls.ec2_client.deregister_image,
                                   image["image_id"])

        for image in cls.images.itervalues():
            def _state():
                retr = cls.ec2_client.get_image(image["image_id"])
                return retr.state
            state = state_wait(_state, "available")
            if state != "available":
                for _image in cls.images.itervalues():
                    ec2_client.deregister_image(_image["image_id"])
                raise RegisterImageException(image_id=image["image_id"])
Exemplo n.º 9
0
    def assertAddressDissasociatedWait(self, address):
        def _disassociate():
            cli = self.ec2_client
            addresses = cli.get_all_addresses(addresses=(address.public_ip, ))
            if len(addresses) != 1:
                return "INVALID"
            if addresses[0].instance_id:
                LOG.info("%s associated to %s", address.public_ip,
                         addresses[0].instance_id)
                return "ASSOCIATED"
            return "DISASSOCIATED"

        state = state_wait(_disassociate, "DISASSOCIATED",
                           set(("ASSOCIATED", "DISASSOCIATED")))
        self.assertEqual(state, "DISASSOCIATED")
Exemplo n.º 10
0
    def assertAddressDissasociatedWait(self, address):

        def _disassociate():
            cli = self.ec2_client
            addresses = cli.get_all_addresses(addresses=(address.public_ip,))
            if len(addresses) != 1:
                return "INVALID"
            if addresses[0].instance_id:
                LOG.info("%s associated to %s",
                         address.public_ip,
                         addresses[0].instance_id)
                return "ASSOCIATED"
            return "DISASSOCIATED"

        state = state_wait(_disassociate, "DISASSOCIATED",
                           set(("ASSOCIATED", "DISASSOCIATED")))
        self.assertEqual(state, "DISASSOCIATED")
    def test_integration_1(self):
        # EC2 1. integration test (not strict)
        image_ami = self.ec2_client.get_image(self.images["ami"]["image_id"])
        sec_group_name = rand_name("securitygroup-")
        group_desc = sec_group_name + " security group description "
        security_group = self.ec2_client.create_security_group(sec_group_name,
                                                               group_desc)
        self.addResourceCleanUp(self.destroy_security_group_wait,
                                security_group)
        self.ec2_client.authorize_security_group(sec_group_name,
                                                 ip_protocol="icmp",
                                                 cidr_ip="0.0.0.0/0",
                                                 from_port=-1,
                                                 to_port=-1)
        self.ec2_client.authorize_security_group(sec_group_name,
                                                 ip_protocol="tcp",
                                                 cidr_ip="0.0.0.0/0",
                                                 from_port=22,
                                                 to_port=22)
        reservation = image_ami.run(kernel_id=self.images["aki"]["image_id"],
                                    ramdisk_id=self.images["ari"]["image_id"],
                                    instance_type=self.instance_type,
                                    key_name=self.keypair_name,
                                    security_groups=(sec_group_name,))
        self.addResourceCleanUp(self.destroy_reservation,
                                reservation)
        volume = self.ec2_client.create_volume(1, self.zone)
        self.addResourceCleanUp(self.destroy_volume_wait, volume)
        instance = reservation.instances[0]

        def _instance_state():
            instance.update(validate=True)
            return instance.state

        def _volume_state():
            volume.update(validate=True)
            return volume.status

        LOG.info("state: %s", instance.state)
        if instance.state != "running":
            self.assertInstanceStateWait(_instance_state, "running")

        address = self.ec2_client.allocate_address()
        rcuk_a = self.addResourceCleanUp(address.delete)
        address.associate(instance.id)

        rcuk_da = self.addResourceCleanUp(address.disassociate)
        #TODO(afazekas): ping test. dependecy/permission ?

        self.assertVolumeStatusWait(_volume_state, "available")
        #NOTE(afazekas): it may be reports availble before it is available

        ssh = RemoteClient(address.public_ip,
                           self.os.config.compute.ssh_user,
                           pkey=self.keypair.material)
        text = rand_name("Pattern text for console output -")
        resp = ssh.write_to_console(text)
        self.assertFalse(resp)

        def _output():
            output = instance.get_console_output()
            return output.output

        re_search_wait(_output, text)
        part_lines = ssh.get_partitions().split('\n')
        # "attaching" invalid EC2 state ! #1074901
        volume.attach(instance.id, "/dev/vdh")

        #self.assertVolumeStatusWait(_volume_state, "in-use")  # #1074901
        re_search_wait(_volume_state, "in-use")

        #NOTE(afazekas):  Different Hypervisor backends names
        # differently the devices,
        # now we just test is the partition number increased/decrised

        def _part_state():
            current = ssh.get_partitions().split('\n')
            if current > part_lines:
                return 'INCREASE'
            if current < part_lines:
                return 'DECREASE'
            return 'EQUAL'

        state_wait(_part_state, 'INCREASE')
        part_lines = ssh.get_partitions().split('\n')

        #TODO(afazekas): Resource compare to the flavor settings

        volume.detach()  # "detaching" invalid EC2 status #1074901

        #self.assertVolumeStatusWait(_volume_state, "available")
        re_search_wait(_volume_state, "available")
        LOG.info("Volume %s state: %s", volume.id, volume.status)

        state_wait(_part_state, 'DECREASE')

        instance.stop()
        address.disassociate()
        self.assertAddressDissasociatedWait(address)
        self.cancelResourceCleanUp(rcuk_da)
        address.release()
        self.assertAddressReleasedWait(address)
        self.cancelResourceCleanUp(rcuk_a)

        LOG.info("state: %s", instance.state)
        if instance.state != "stopped":
            self.assertInstanceStateWait(_instance_state, "stopped")
Exemplo n.º 12
0
    def test_integration_1(self):
        """EC2 1. integration test (not strict)"""
        image_ami = self.ec2_client.get_image(self.images["ami"]["image_id"])
        sec_group_name = rand_name("securitygroup-")
        group_desc = sec_group_name + " security group description "
        security_group = self.ec2_client.create_security_group(
            sec_group_name, group_desc)
        self.addResourceCleanUp(self.destroy_security_group_wait,
                                security_group)
        self.ec2_client.authorize_security_group(sec_group_name,
                                                 ip_protocol="icmp",
                                                 cidr_ip="0.0.0.0/0",
                                                 from_port=-1,
                                                 to_port=-1)
        self.ec2_client.authorize_security_group(sec_group_name,
                                                 ip_protocol="tcp",
                                                 cidr_ip="0.0.0.0/0",
                                                 from_port=22,
                                                 to_port=22)
        reservation = image_ami.run(kernel_id=self.images["aki"]["image_id"],
                                    ramdisk_id=self.images["ari"]["image_id"],
                                    instance_type=self.instance_type,
                                    key_name=self.keypair_name,
                                    security_groups=(sec_group_name, ))
        self.addResourceCleanUp(self.destroy_reservation, reservation)
        volume = self.ec2_client.create_volume(1, self.zone)
        self.addResourceCleanUp(self.destroy_volume_wait, volume)
        instance = reservation.instances[0]

        def _instance_state():
            instance.update(validate=True)
            return instance.state

        def _volume_state():
            volume.update(validate=True)
            return volume.status

        LOG.info("state: %s", instance.state)
        if instance.state != "running":
            self.assertInstanceStateWait(_instance_state, "running")

        address = self.ec2_client.allocate_address()
        rcuk_a = self.addResourceCleanUp(address.delete)
        address.associate(instance.id)

        rcuk_da = self.addResourceCleanUp(address.disassociate)
        #TODO(afazekas): ping test. dependecy/permission ?

        self.assertVolumeStatusWait(_volume_state, "available")
        #NOTE(afazekas): it may be reports availble before it is available

        ssh = RemoteClient(address.public_ip,
                           self.os.config.compute.ssh_user,
                           pkey=self.keypair.material)
        text = rand_name("Pattern text for console output -")
        resp = ssh.write_to_console(text)
        self.assertFalse(resp)

        def _output():
            output = instance.get_console_output()
            return output.output

        re_search_wait(_output, text)
        part_lines = ssh.get_partitions().split('\n')
        # "attaching" invalid EC2 state ! #1074901
        volume.attach(instance.id, "/dev/vdh")

        #self.assertVolumeStatusWait(_volume_state, "in-use")  # #1074901
        re_search_wait(_volume_state, "in-use")

        #NOTE(afazekas):  Different Hypervisor backends names
        # differently the devices,
        # now we just test is the partition number increased/decrised

        def _part_state():
            current = ssh.get_partitions().split('\n')
            if current > part_lines:
                return 'INCREASE'
            if current < part_lines:
                return 'DECREASE'
            return 'EQUAL'

        state_wait(_part_state, 'INCREASE')
        part_lines = ssh.get_partitions().split('\n')

        #TODO(afazekas): Resource compare to the flavor settings

        volume.detach()  # "detaching" invalid EC2 status #1074901

        #self.assertVolumeStatusWait(_volume_state, "available")
        re_search_wait(_volume_state, "available")
        LOG.info("Volume %s state: %s", volume.id, volume.status)

        state_wait(_part_state, 'DECREASE')

        instance.stop()
        address.disassociate()
        self.assertAddressDissasociatedWait(address)
        self.cancelResourceCleanUp(rcuk_da)
        address.release()
        self.assertAddressReleasedWait(address)
        self.cancelResourceCleanUp(rcuk_a)

        LOG.info("state: %s", instance.state)
        if instance.state != "stopped":
            self.assertInstanceStateWait(_instance_state, "stopped")
Exemplo n.º 13
0
 def waitSnapshotStatus(self, lfunction, wait_for):
     state = state_wait(lfunction, wait_for, self.valid_snapshot_status)
     self.assertIn(state, self.valid_snapshot_status)
     return state
Exemplo n.º 14
0
 def waitVolumeStatus(self, lfunction, wait_for):
     state = state_wait(lfunction, wait_for, self.valid_volume_status)
     self.assertIn(state, self.valid_volume_status)
     return state
Exemplo n.º 15
0
 def waitInstanceState(self, lfunction, wait_for):
     state = state_wait(lfunction, wait_for, self.valid_instance_state)
     self.assertIn(state, self.valid_instance_state)
     return state