def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument('--clean_on_exit',
                                 action='store_true', default=True,
                                 help='Boolean, used to flag whether to run clean up method after running test list)')
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)

        self.get_args()
        # ## Setup basic eutester object
        if self.args.region:
            self.tester = CWops(credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops(config_file=self.args.config, password=self.args.password,
                                  credpath=self.args.credpath)
        self.start_time = str(int(time.time()))
        self.zone = self.tester.get_zones()
        self.namespace = 'Namespace-' + self.start_time
        self.keypair = self.tester.add_keypair()
        self.group = self.tester.add_group()
        ### Setup AutoScaling
        self.setUpAutoscaling()
        ### Create Dimensions used in tests
        self.instanceDimension = newDimension('InstanceId', self.instanceid)
        self.volumeDimension = newDimension('VolumeId', self.volume.id)
        self.autoScalingDimension = newDimension('AutoScalingGroupName', self.auto_scaling_group_name)
        ### Setup Alarms
        self.setUpAlarms()
        ### Wait for metrics to populate, timeout 30 minute
        self.tester.wait_for_result(self.IsMetricsListPopulated, result=True, timeout=1800)
 def __init__(self, extra_args=None):
     self.setuptestcase()
     self.setup_parser()
     self.parser.add_argument('--template_urls', dest='template_urls',
                              help='comma separated list of template_urls',
                              default=None)
     self.parser.add_argument('--timeout', dest='timeout',
                              help='number of seconds to wait for stacks to complete',
                              default=300)
     if extra_args:
         for arg in extra_args:
             self.parser.add_argument(arg)
     self.get_args()
     self.show_args()
     self.template_urls = self.args.template_urls.split(',')
     self.timeout = int(self.args.timeout)
     # Setup basic eutester object
     if self.args.region:
         self.tester = CFNops(credpath=self.args.credpath, region=self.args.region)
     else:
         self.tester = Eucaops(credpath=self.args.credpath, config_file=self.args.config,
                               password=self.args.password)
     # Generate a keypair for the instance
     self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
     self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
     self.stacks = []
Example #3
0
class ConsoleCleanUp(EutesterTestCase):
    def __init__(self, extra_args= None, **kwargs):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        for kwarg in kwargs:
            self.args[kwarg] = kwarg[kwarg]
        # Setup basic eutester object
        if self.args.region:
            self.tester = EC2ops( credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops( credpath=self.args.credpath, config_file=self.args.config,password=self.args.password)
        self.tester.poll_count = 120

    def scan_and_clean_all_existing_resources(self):
        self.tester.test_resources['addresses']=self.tester.ec2.get_all_addresses()
        self.tester.test_resources['auto-scaling-groups']=self.tester.autoscale.get_all_groups()
        self.tester.test_resources['volumes']=self.tester.ec2.get_all_volumes()
        self.tester.test_resources['keypairs']=self.tester.ec2.get_all_key_pairs()
        self.tester.test_resources['snapshots']=self.tester.ec2.get_all_snapshots()
        self.tester.test_resources['security-groups']=self.tester.ec2.get_all_security_groups()
        self.tester.test_resources['reservations']=self.tester.ec2.get_all_instances()
        self.tester.test_resources['launch-configurations']=self.tester.autoscale.get_all_launch_configurations()
        self.tester.debug("Attempting to clean up:\n" + str(self.tester.test_resources))
        self.tester.cleanup_artifacts()
Example #4
0
class Euca5845(unittest.TestCase):
    def setUp(self):
        self.conf = "cloud.conf"
        self.tester = Eucaops(config_file=self.conf, password="******")
        self.OK = "\033[1m\033[37m\033[42m"
        self.ENDC = "\033[0m"

    def tearDown(self):
        self.tester.cleanup_artifacts()
        self.tester.delete_keypair(self.keypair)
        self.tester.local("rm " + self.keypair.name + ".pem")
        shutil.rmtree(self.tester.credpath)

    def doAuth(self, groupName):
        self.keypair = self.tester.add_keypair()
        self.group = self.tester.add_group(groupName)
        self.tester.authorize_group(self.group)

    def testName(self):
        # Group name with NON ASCII Character
        badGroupName = "lin¢ux"
        try:
            self.doAuth(badGroupName)
        except Exception as err:
            if str(err).count("InvalidParameterValue") > 0:
                print self.OK + err.args[2] + self.ENDC
                pass
            else:
                self.fail("FAILED : NON ASCII Character allowed.")
        print "SUCCESS"
Example #5
0
    def __init__(self, extra_args= None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        if self.args.emi:
            self.tester = Eucaops(credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath)

       ### Add and authorize a group for the instance
        self.group = self.tester.add_group(group_name="group-" + str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name )
        self.tester.authorize_group_by_name(group_name=self.group.name, port=-1, protocol="icmp" )
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair( "keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)

        self.image = self.args.emi
        if not self.image:
            self.image = self.tester.get_emi(root_device_type="instance-store")
        self.address = None
    def __init__(self):
        #### Pre-conditions
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument("--test-zone", default="PARTI00")
        self.parser.add_argument("--test-emi", default=None)
        self.parser.add_argument("--build-number", default='')
        self.get_args()

        # Setup basic eutester object
        if not self.args.credpath:
            self.tester = Eucaops(config_file=self.args.config, password=self.args.password)
        else:
            self.tester = Eucaops(credpath=self.args.credpath)
        self.reservation = None

        ### Generate a group for the instance
        self.group = self.tester.add_group(group_name="inst-kvm-grp-" + str(time.time()).replace(".", "") +
                                                      self.tester.id_generator() + "-" + self.args.build_number)
        self.tester.authorize_group_by_name(group_name=self.group.name)
        self.tester.authorize_group_by_name(group_name=self.group.name, port=-1, protocol="icmp")

        self.keypair = self.tester.add_keypair("inst-kvm-" + str(time.time()).replace(".", "") +
                                               self.tester.id_generator() + "-" + self.args.build_number)

        if not self.args.emi:
            self.image = self.tester.get_emi(root_device_type="instance-store")
        else:
            self.image = self.tester.get_emi(self.args.test_emi)
Example #7
0
 def test1_Instance(self):
     """Instance checks including reachability and ephemeral storage"""
     for instance in self.reservation.instances:
         self.assertTrue( self.tester.wait_for_reservation(self.reservation) ,'Instance did not go to running')
         self.assertNotEqual( instance.public_dns_name, instance.private_ip_address, 'Public and private IP are the same')
         self.assertTrue( self.tester.ping(instance.public_dns_name), 'Could not ping instance')
         instance_ssh = Eucaops( hostname=instance.public_dns_name,  keypath= self.keypath)
         self.assertTrue( instance_ssh.found("ls -1 " + self.ephemeral,  self.ephemeral),  'Did not find ephemeral storage at ' + self.ephemeral)
         self.assertTrue( self.tester.terminate_instances(self.reservation), 'Failure when terminating instance')
class CloudFormationTemplateURLTests(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument('--template_urls', dest='template_urls',
                                 help='comma separated list of template_urls',
                                 default=None)
        self.parser.add_argument('--timeout', dest='timeout',
                                 help='number of seconds to wait for stacks to complete',
                                 default=300)
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        self.show_args()
        self.template_urls = self.args.template_urls.split(',')
        self.timeout = int(self.args.timeout)
        # Setup basic eutester object
        if self.args.region:
            self.tester = CFNops(credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath, config_file=self.args.config,
                                  password=self.args.password)
        # Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        self.stacks = []

    def Stack_Template_URL_Test(self):
        for url in self.template_urls:
            # get template name from URL, remove file extension and any "-"
            template = os.path.splitext(url.rsplit('/', 1)[1])[0].replace("-", "")
            self.stack_name = template + str(os.urandom(8).encode('hex'))
            self.stacks.append(self.stack_name)
            self.template_parameters = [('KeyName', self.keypair.name), ('ImageId', self.tester.get_emi().id)]
            self.tester.create_stack(stack_name=self.stack_name,
                                     template_body=None,
                                     template_url=url,
                                     parameters=self.template_parameters)

            def stack_completed():
                stack_status = False
                if len(self.tester.cloudformation.describe_stack_events(self.stack_name)) > 0:
                    stack_info = self.tester.cloudformation.describe_stack_events(self.stack_name)
                    for inf in stack_info:
                        if (inf.logical_resource_id == self.stack_name) and (inf.resource_status == "CREATE_COMPLETE"):
                            self.debug("Stack Logical Resource: " + inf.logical_resource_id)
                            self.debug("Stack Resource Status: " + inf.resource_status)
                            stack_status = True
                return stack_status
            self.tester.wait_for_result(stack_completed, True, timeout=self.timeout)

    def clean_method(self):
        self.tester.cleanup_artifacts()
        for stack in self.stacks:
            self.tester.delete_stack(stack)
Example #9
0
class SOSreport(EutesterTestCase):
    def __init__(self):
        self.setuptestcase()
        self.setup_parser()
        self.start_time = int(time.time())
        self.parser.add_argument("--ticket-number", default=str(self.start_time))
        self.parser.add_argument("--timeout", default=1200, type=int)
        self.parser.add_argument("--remote-dir", default="/root/")
        self.parser.add_argument("--local-dir", default=os.getcwd())
        self.parser.add_argument(
            "--package-url", default="http://mongo.beldurnik.com/RPMS/eucalyptus-sos-plugins-0.1.1-0.el6.noarch.rpm"
        )
        self.get_args()
        self.remote_dir = self.args.remote_dir + "/euca-sosreport-" + self.args.ticket_number + "/"
        # Setup basic eutester object
        self.tester = Eucaops(config_file=self.args.config, password=self.args.password, download_creds=False)

    def clean_method(self):
        pass

    def Install(self):
        """
        This is where the test description goes
        """
        for machine in self.tester.get_component_machines():
            assert isinstance(machine, Machine)
            if machine.distro.name is "vmware":
                continue
            machine.install("sos")
            machine.sys("yum install -y " + self.args.package_url)

    def Run(self):
        error_msg = ""
        for machine in self.tester.get_component_machines():
            try:
                assert isinstance(machine, Machine)
                if machine.distro.name is "vmware":
                    continue
                machine.sys("mkdir -p " + self.args.remote_dir)
                machine.sys(
                    "sosreport --batch --skip-plugins=emc --tmp-dir "
                    + self.args.remote_dir
                    + " --ticket-number "
                    + str(self.args.ticket_number),
                    code=0,
                    timeout=self.args.timeout,
                )
            except Exception, e:
                error_msg += "Error running SOS report on:" + str(machine.hostname) + ". Error:" + str(e)
        if error_msg:
            raise Exception(error_msg)
Example #10
0
class SOSreport(EutesterTestCase):
    def __init__(self):
        self.setuptestcase()
        self.setup_parser()
        self.start_time = int(time.time())
        self.parser.add_argument("--ticket-number", default=str(self.start_time))
        self.parser.add_argument("--remote-dir", default="/root/")
        self.parser.add_argument("--local-dir", default=os.getcwd())
        self.parser.add_argument("--package-url", default="http://mongo.beldurnik.com/RPMS/eucalyptus-sos-plugins-0.1.1-0.el6.noarch.rpm")
        self.get_args()
        self.remote_dir = self.args.remote_dir + "/euca-sosreport-" + self.args.ticket_number + "/"
        # Setup basic eutester object
        self.tester = Eucaops( config_file=self.args.config,password=self.args.password, download_creds=False)

    def clean_method(self):
        pass

    def Install(self):
        """
        This is where the test description goes
        """
        for machine in self.tester.get_component_machines():
            assert isinstance(machine, Machine)
            if machine.distro.name is "vmware":
                continue
            machine.install("sos")
            machine.sys("yum install -y " + self.args.package_url)

    def Run(self):
        for machine in self.tester.get_component_machines():
            assert isinstance(machine, Machine)
            if machine.distro.name is "vmware":
                continue
            machine.sys("mkdir -p " + self.args.remote_dir)
            machine.sys("sosreport --batch --skip-plugins=emc --tmp-dir " + self.args.remote_dir + " --ticket-number " + str(self.args.ticket_number),code=0)

    def Download(self):
        for machine in self.tester.get_component_machines():
            assert isinstance(machine, Machine)
            if machine.distro.name is "vmware":
                continue
            remote_tarball_path = machine.sys("ls -1 " + self.args.remote_dir + "*" + str(self.args.ticket_number) + "*", code=0)[0]
            tarball = remote_tarball_path.split("/")[-1]
            local_tarball_path = self.args.local_dir + '/' + tarball
            self.tester.debug("Downloading file to: " + local_tarball_path)
            machine.sftp.get(remote_tarball_path, local_tarball_path)

    def RunAll(self):
        self.Install()
        self.Run()
        self.Download()
Example #11
0
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()

        # Setup basic eutester object
        if self.args.region:
            self.tester = ELBops(credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops(
                credpath=self.args.credpath, config_file=self.args.config, password=self.args.password
            )
        self.tester.poll_count = 120

        ### Add and authorize a group for the instance
        self.group = self.tester.add_group(group_name="group-" + str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name)
        self.tester.authorize_group_by_name(group_name=self.group.name, port=-1, protocol="icmp")
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = "%s/%s.pem" % (os.curdir, self.keypair.name)

        ### Get an image
        self.image = self.args.emi
        if not self.image:
            self.image = self.tester.get_emi(root_device_type="instance-store")

        ### Populate available zones
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name

        self.load_balancer_port = 80

        (self.web_servers, self.filename) = self.tester.create_web_servers(
            keypair=self.keypair,
            group=self.group,
            zone=self.zone,
            port=self.load_balancer_port,
            filename="instance-name",
            image=self.image,
        )

        self.load_balancer = self.tester.create_load_balancer(
            zones=[self.zone], name="test-" + str(time.time()), load_balancer_port=self.load_balancer_port
        )
        assert isinstance(self.load_balancer, LoadBalancer)
        self.tester.register_lb_instances(self.load_balancer.name, self.web_servers.instances)
Example #12
0
 def __init__(self, extra_args= None):
     self.setuptestcase()
     self.setup_parser()
     if extra_args:
         for arg in extra_args:
             self.parser.add_argument(arg)
     self.get_args()
     # Setup basic eutester object
     if self.args.region:
         self.tester = CWops( credpath=self.args.credpath, region=self.args.region)
     else:
         self.tester = Eucaops(config_file=self.args.config, password=self.args.password, credpath=self.args.credpath)
     self.start_time =  str(int(time.time()))
     self.namespace = "Namespace-" + self.start_time
Example #13
0
    def __init__(self):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument("-b", "--buckets", type=int, default=5)
        self.parser.add_argument("-o", "--objects", type=int, default=5)
        self.parser.add_argument("-T", "--threads", type=int, default=5)
        self.parser.add_argument("-S", "--object-size", type=int, default=64, help="Object size in KB")
        self.parser.add_argument("-M", "--mpu-threshold", type=int, default=5120,
                                 help="Multipart upload is used when the object size is bigger than the mpu-threshold "
                                      "value in Kilobyte. Any value less than 5120KB will result single file upload. "
                                      "Default value is used when not passed as an argument.")
        self.get_args()
        # Setup basic eutester object
        if self.args.region:
            self.tester = S3ops( credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath, config_file=self.args.config,password=self.args.password)
        self.start = time.time()

        self.bucket_names = []
        self.bucket_name = "concurrency-" + str(int(self.start)) + "-"

        for i in xrange(self.args.buckets):
            bucket_name = self.bucket_name + str(i)
            self.bucket_names.append(bucket_name)
            self.tester.create_bucket(bucket_name)

        self.temp_files = []
Example #14
0
    def __init__(self, extra_args= None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.parser.add_argument('--imgurl',
                        help="BFEBS Image to splat down", default=None)
        self.get_args()
        self.tester = Eucaops( config_file=self.args.config, password=self.args.password)
        self.numberOfNodes = self.tester.service_manager.get_all_node_controllers()
        if len(self.numberOfNodes) < 2:
            exit("Not enough NCs to test instance migration.")

        self.group = self.tester.add_group(group_name="group-" + str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name )
        self.tester.authorize_group_by_name(group_name=self.group.name, port=-1, protocol="icmp" )

        self.keypair = self.tester.add_keypair( "keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)

        self.image = self.args.emi
        if not self.image:
            self.image = self.tester.get_emi(root_device_type="instance-store")
        self.numberOfResources = 3
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name

        try:
            self.tester.get_emi(root_device_type="ebs")
        except:
            bfebs = self.do_with_args(BFEBSBasics)
            bfebs.RegisterImage()
Example #15
0
 def get_creds():
     try:
         self.tester = Eucaops(config_file=self.args.config_file, password=self.args.password,download_creds=False)
         self.tester.get_credentials()
         return True
     except Exception:
         return False
Example #16
0
 def __init__(self, download_creds=False, extra_args= None):
     self.setuptestcase()
     self.setup_parser()
     self.parser.add_argument("--euca-url",)
     self.parser.add_argument("--enterprise-url")
     self.parser.add_argument("--branch")
     self.parser.add_argument("--nogpg",action='store_true')
     self.parser.add_argument("--nightly",action='store_true')
     self.parser.add_argument("--lvm-extents")
     self.parser.add_argument("--vnet-mode", default="MANAGED-NOVLAN")
     self.parser.add_argument("--vnet-subnet", default="1.0.0.0")
     self.parser.add_argument("--vnet-netmask", default="255.255.0.0")
     self.parser.add_argument("--vnet-publicips")
     self.parser.add_argument("--vnet_addrspernet", default="32")
     self.parser.add_argument("--vnet_privinterface", default="br0")
     self.parser.add_argument("--vnet_pubinterface", default="br0")
     self.parser.add_argument("--vnet_bridge", default="br0")
     self.parser.add_argument("--vnet-dns", default="8.8.8.8")
     self.parser.add_argument("--root-lv", default="/dev/vg01/")
     self.parser.add_argument("--dnsdomain")
     self.parser.add_argument("--block-device-manager", default="das")
     if extra_args:
         for arg in extra_args:
             self.parser.add_argument(arg)
     self.get_args()
     # Setup basic eutester object
     self.tester = Eucaops( config_file=self.args.config_file, password=self.args.password, download_creds=download_creds)
Example #17
0
    def __init__(self):
        extra_args = ['--size', '--repo-url', '--packages', '--user-data']
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        if self.args.region:
            self.tester = EC2ops( credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops(config_file=self.args.config, password=self.args.password, credpath=self.args.credpath)
        self.tester.poll_count = 120

        ### Add and authorize a group for the instance
        self.group = self.tester.add_group(group_name="group-" + str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name )
        self.tester.authorize_group_by_name(group_name=self.group.name, port=-1, protocol="icmp" )
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair( "keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        if not self.args.emi:
            raise Exception("Must pass base image id to use as parameter --emi")
        self.image =  self.tester.get_emi(self.args.emi)
        self.address = None
        self.volume = None
        self.private_addressing = False
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name
        self.reservation = None
Example #18
0
 def __init__(self, config_file="cloud.conf", password="******"):
     self.tester = Eucaops( config_file=config_file, password=password)
     self.servman = self.tester.service_manager
     self.tester.poll_count = 120
     ### Add and authorize a group for the instance
     self.start_time = str(int(time.time()))
     self.group = self.tester.add_group(group_name="group-" + self.start_time )
     self.tester.authorize_group_by_name(group_name=self.group.name )
     self.tester.authorize_group_by_name(group_name=self.group.name, port=-1, protocol="icmp" )
     ### Generate a keypair for the instance
     self.keypair = self.tester.add_keypair( "keypair-" + self.start_time)
     self.keypath = os.curdir + "/" + self.keypair.name + ".pem"
     self.image = self.tester.get_emi(root_device_type="instance-store")
     self.reservation = None
     self.private_addressing = False
     self.bucket_prefix = "buckettestsuite-" + self.start_time + "-"
     self.test_user_id = self.tester.s3.get_canonical_user_id()
     zones = self.tester.ec2.get_all_zones()
     self.zone = random.choice(zones).name
     
     
     ### Create standing resources that will be checked after all failures
     ### Instance, volume, buckets
     ### 
     self.standing_reservation = self.tester.run_instance(keypair=self.keypair.name,group=self.group.name, zone=self.zone)
     self.volume = self.tester.create_volume(self.zone)
     self.device = self.standing_reservation.instances[0].attach_volume(self.volume)
     self.standing_bucket_name = "failover-bucket-" + self.start_time
     self.standing_bucket = self.tester.create_bucket(self.standing_bucket_name)
     self.standing_key_name = "failover-key-" + self.start_time
     self.standing_key = self.tester.upload_object(self.standing_bucket_name, self.standing_key_name)
     self.standing_key = self.tester.get_objects_by_prefix(self.standing_bucket_name, self.standing_key_name)
Example #19
0
    def __init__(self, extra_args= None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        if self.args.region:
            self.tester = EC2ops( credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops(config_file=self.args.config, password=self.args.password, credpath=self.args.credpath)
        self.tester.poll_count = 120

        ### Add and authorize a group for the instance
        self.group = self.tester.add_group(group_name="group-" + str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name )
        self.tester.authorize_group_by_name(group_name=self.group.name, port=-1, protocol="icmp" )
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair( "keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        self.image = self.args.emi
        if not self.image:
            self.image = self.tester.get_emi(root_device_type="instance-store")
        self.address = None
        self.volume = None
        self.private_addressing = False
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name
        self.reservation = None
Example #20
0
    def __init__(self, extra_args= None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        self.tester = Eucaops( credpath=self.args.credpath, config_file=self.args.config,password=self.args.password)
        self.tester.poll_count = 120

        self.security_groups = []

        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair( "keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        self.image = self.args.emi
        if not self.image:
            self.image = self.tester.get_emi(root_device_type="instance-store")
        self.address = None
        self.volume = None
        self.snapshot = None
        self.private_addressing = False
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name
        self.reservation = None
Example #21
0
    def __init__(self):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument("--endpoint", default=None)
        self.get_args()
        # Setup basic eutester object
        if self.args.endpoint:
            self.tester = S3ops(credpath=self.args.credpath, endpoint=self.args.endpoint)
        else:
            self.tester = Eucaops( credpath=self.args.credpath, config_file=self.args.config, password=self.args.password)

        self.bucket_prefix = "eutester-" + str(int(time.time())) + "-"
        self.buckets_used = set()
        random.seed(time.time())
        self.test_bucket_name = self.bucket_prefix + str(random.randint(0,100))
        self.test_bucket = self.tester.create_bucket(self.test_bucket_name)
        self.buckets_used.add(self.test_bucket_name)
        #Create some test data for the objects
        def ensure_bucket_exists():
            try:
                self.tester.s3.get_bucket(self.test_bucket_name)
                return True
            except Exception:
                return False
        self.tester.wait_for_result(ensure_bucket_exists, True)
        self.test_object_data = ""
        for i in range(0, self.data_size):
            self.test_object_data += chr(random.randint(32,126))
        print "Generated data for objects: " + self.test_object_data
    def __init__(self):
        self.setuptestcase()
        self.setup_parser()
        self.get_args()
        # Setup basic eutester object
        self.tester = Eucaops( config_file=self.args.config_file, password=self.args.password)
        self.tester.poll_count = 120

        ### Add and authorize a group for the instance
        self.group = self.tester.add_group(group_name="group-" + str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name )
        self.tester.authorize_group_by_name(group_name=self.group.name, port=-1, protocol="icmp" )
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair( "keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        self.image = self.tester.get_emi(root_device_type="instance-store")
        self.reservation = None
        self.private_addressing = False
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name
        clcs = self.tester.get_component_machines("clc")
        if len(clcs) is 0:
            raise Exception("No CLC found")
        else:
            self.clc = clcs[0]
        self.cur_time = str(int(time.time()))
        self.ncs = self.tester.get_component_machines("nc")
Example #23
0
class MyTestCase(EutesterTestCase):
    def __init__(self, config_file=None, password=None):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument("--command", default="free")
        self.parser.add_argument("--component", default=None)
        self.get_args()
        # Setup basic eutester object
        self.tester = Eucaops( config_file=self.args.config_file, password=self.args.password,download_creds=False)

    def clean_method(self):
        pass

    def MyTestUnit(self):
        """
        A test description must go here......
        This test will simply run an instance and check that it is reachable via ssh
        """
        target_machines = []
        if not self.args.component:
            target_machines = self.tester.config['machines']
        else:
            target_machines = self.tester.get_component_machines(self.args.component)

        for machine in target_machines:
            machine.sys(self.args.command)
    def __init__(self, **kwargs):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument("--admin-name", dest='admin_name', default=None)
        self.parser.add_argument("--admin-email", dest='admin_email', default=None)
        self.parser.add_argument("--template-path", dest='template_path', default=None,
                                 help='path to riak templates, default is '
                                      '<eutester_dir>/testcases/cloud_admin/riak_cs/templates/')
        self.parser.add_argument("--riak-cs-port", default="9090")
        self.parser.add_argument("--bare-machines", dest='bare_machines', default=None,
                                 help='Comma delimited list of hosts to install riak on')
        self.parser.add_argument("--machine-password", dest='machine_password', default=None,
                                 help='password used to log into remote machines when '
                                      'installing riak')
        self.parser.add_argument("--walrus-fallback", dest='walrus_fallback', default=True,
                                 help='Allow test to configure system for Walrus in the case'
                                      'Riak fails to install or a riak component(s) is not listed')
        self.parser.add_argument("--basho-url", dest='basho_url',
                                 default='http://yum.basho.com/gpg/basho-release-6-1.noarch.rpm',
                                 help="default basho repo")
        self.get_args()
        # Allow __init__ to get args from __init__'s kwargs or through command line parser...
        for kw in kwargs:
            print 'Setting kwarg:'+str(kw)+" to "+str(kwargs[kw])
            self.set_arg(kw ,kwargs[kw])
        self.show_args()
        # Setup basic eutester object
        self.tester = Eucaops( config_file=self.args.config,password=self.args.password)
        self.machines = []
        if self.args.bare_machines:
            b_machines = self.args.bare_machines
            if not isinstance(b_machines, list) and isinstance(b_machines, str):
                b_machines = b_machines.split(',')
            else:
                raise ValueError('Unknown type for machine arg:"{0}", type:"{1}"'
                                 .format(b_machines, type(b_machines)))
            for mach in b_machines:
                if not isinstance(mach, Machine):
                    if not self.args.machine_password:
                        raise ValueError('Must provide machine password for machine list')
                    mach = Machine(str(mach).strip(), password=self.args.machine_password)
                self.machines.append(mach)
        else:
            try:
                self.machines = self.tester.get_component_machines("riak")
            except IndexError as ex:
                self.tester.info("No Riak component found in component specification. ")

                if self.args.walrus_fallback:
                    self.tester.info('walrus_fallback set to True, attempting to configure for'
                                     'walrus...')
                    self.configure_eucalyptus_for_walrus()
                else:
                    raise
        self.template_dir = self.args.template_path or os.path.join(self._get_script_filepath(),
                                                                    'templates/')
        self.primary_machine = None
        self.user_dict = None
        self.args.admin_name = self.args.admin_name or 'testuser_' + str(int(time.time()))
        self.args.admin_email = self.args.admin_email or self.args.admin_name +'@testemail'
Example #25
0
 def setUp(self):
     self.conf = "cloud.conf" 
     self.cond = 1     
     self.tester  = Eucaops( config_file=self.conf, password="******" )
     self.doAuth()
     self.clc1 = self.tester.service_manager.get_enabled_clc()
     self.IP = self.tester.get_ec2_ip()
Example #26
0
 def __init__(self, 
              name=None,
              args=None,
              tester=None, 
              zone=None, 
              config_file='../input/2b_tested.lst', 
              password="******", 
              inst_pass=None,
              credpath=None, 
              volumes=None, 
              keypair=None, 
              group=None, 
              emi=None,
              root_device_type='instance-store',
              vmtype='c1.medium',
              eof=1):
     
     self.args = args
     self.setuptestcase(name)
     if tester is None:
         self.tester = Eucaops( config_file=config_file,password=password,credpath=credpath)
     else:
         self.tester = tester
     self.tester.exit_on_fail = eof
 
     self.testlist =[]
     self.inst_pass=inst_pass
     if emi:
         self.image = self.tester.get_emi(emi=emi)
     else:
         self.image = self.tester.get_emi(root_device_type=root_device_type, not_location='windows')
     
     self.vmtype = vmtype
     self.zone = None    
     self.zonelist = []
         
     #create some zone objects and append them to the zonelist
     if self.zone:
         self.zone = TestZone(zone)
         self.zonelist.append(self.zone)
     else: 
         self.setup_testzones()
 
     #If the list of volumes passed in looks good, sort them into the zones
     if self.volumes_list_check(volumes):
         self.sort_volumes(volumes)
         
     #Setup our security group for later use
     if (group is not None):
         self.group = group
     else:
         group_name='EbsTestGroup'
         
         try:
             self.group = self.tester.add_group(group_name,fail_if_exists=False)
             self.tester.authorize_group_by_name(self.group.name)
             self.tester.authorize_group_by_name(self.group.name,protocol="icmp",port=-1)
         except Exception, e:  
             self.debug(self.tester.get_traceback())  
             raise Exception("Error when setting up group:"+str(group_name)+", Error:"+str(e))   
Example #27
0
 def setUp(self):
     self.conf = "cloud.conf"
     self.fakeId = "OOO000000000"
     self.cmdMod =  " euca-modify-image-attribute --launch-permission "       
     self.tester  = Eucaops( config_file=self.conf, password="******" )
     self.source  = "source " + self.tester.credpath + "/eucarc && "
     self.doAuth()
Example #28
0
 def __init__(self):
     self.setuptestcase()
     self.setup_parser()
     self.parser.add_argument("--img-repo")
     self.get_args()
     # Setup basic eutester object
     self.tester = Eucaops( config_file=self.args.config,password=self.args.password)
Example #29
0
class Euca4128(unittest.TestCase):

    def setUp(self):
        self.conf = "cloud2.conf"       
        self.tester  = Eucaops( config_file=self.conf, password="******" )
        self.cond = 1 
        self.doAuth()

    def tearDown(self):
        #self.tester.cleanup_artifacts() 
        self.tester.delete_keypair(self.keypair)
        self.tester.local("rm " + self.keypair.name + ".pem") 
        shutil.rmtree(self.tester.credpath) 
         
    def runInstances(self):
        #Start instance
        self.reservation = self.tester.run_instance(keypair=self.keypair.name, group=self.group, min=4, max=4, is_reachable=False)
        # Make sure the instance is running       
        for instance in self.reservation.instances:
            if instance.state == "running":
                self.ip = instance.public_dns_name
                self.instanceid = instance.id
                
    def runSysCmd(self, cmd):
        self.source  = "source " + self.tester.credpath + "/eucarc && "
        self.out = self.tester.sys(self.source + cmd) 
         
    def doAuth(self):
        self.keypair = self.tester.add_keypair()
        self.group = self.tester.add_group()
        self.tester.authorize_group(self.group)

    def testName(self):
        #self.emi = self.tester.get_emi()
        #self.zone = self.tester.get_zones().pop()
        #self.runInstances()
        #self.tester.create_volumes(self.zone, count=85)
        self.total = 0
        i = 0
        while i < 10 :
            i += 1
            self.startTime = time.time()
            self.runSysCmd("euca-describe-volumes")
            self.time = time.time() - self.startTime
            self.total += self.time
            
        print self.total / 10
Example #30
0
 def setUp(self):
     self.OK = '\033[1m\033[37m\033[42m'
     self.ENDC = '\033[0m'
     self.conf = 'cloud.conf'
     self.tester  = Eucaops( config_file=self.conf, password='******' )
     self.source  = 'source ' + self.tester.credpath + '/eucarc && '
     self.clc1 = self.tester.service_manager.get_enabled_clc()
     self.doAuth()
Example #31
0
 def setUp(self):
     self.conf = "cloud.conf"
     self.tester = Eucaops(config_file=self.conf, password="******")
     self.cond = 1
     self.doAuth()
Example #32
0
class ReportingBasics(EutesterTestCase):
    def __init__(self, config_file=None, password=None):
        self.setuptestcase()
        # Setup basic eutester object
        self.tester = Eucaops(config_file=config_file, password=password)
        self.tester.poll_count = 120

        ### Add and authorize a group for the instance
        self.group = self.tester.add_group(group_name="group-" +
                                           str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name)
        self.tester.authorize_group_by_name(group_name=self.group.name,
                                            port=-1,
                                            protocol="icmp")
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        self.image = self.tester.get_emi(root_device_type="instance-store")
        self.reservation = None
        self.volume = None
        self.bucket = None
        self.private_addressing = False
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name
        self.clean_method = self.cleanup
        self.cur_time = str(int(time.time()))
        date_fields = time.localtime()
        self.date = str(date_fields.tm_year) + "-" + str(
            date_fields.tm_mon) + "-31"
        clcs = self.tester.get_component_machines("clc")
        if len(clcs) is 0:
            raise Exception("No CLC found")
        else:
            self.clc = clcs[0]
        poll_interval = 1
        write_interval = 1
        size_time_size_unit = "MB"
        size_time_time_unit = "MINS"
        size_unit = "MB"
        time_unit = "MINS"
        self.modify_property(property="reporting.default_poll_interval_mins",
                             value=poll_interval)
        self.modify_property(property="reporting.default_write_interval_mins",
                             value=write_interval)
        self.modify_property(property="reporting.default_size_time_size_unit",
                             value=size_time_size_unit)
        self.modify_property(property="reporting.default_size_time_time_unit",
                             value=size_time_time_unit)
        self.modify_property(property="reporting.default_size_unit",
                             value=size_unit)
        self.modify_property(property="reporting.default_time_unit",
                             value=time_unit)

    def cleanup(self):
        if self.reservation:
            self.assertTrue(self.tester.terminate_instances(self.reservation),
                            "Unable to terminate instance(s)")
        if self.volume:
            self.tester.delete_volume(self.volume)
        if self.bucket:
            self.tester.clear_bucket(self.bucket)
        self.tester.delete_group(self.group)
        self.tester.delete_keypair(self.keypair)
        os.remove(self.keypath)

    def instance(self):
        self.reservation = self.tester.run_instance(self.image,
                                                    keypair=self.keypair.name,
                                                    group=self.group.name,
                                                    zone=self.zone)
        file_size_in_mb = 500
        for instance in self.reservation.instances:
            assert isinstance(instance, EuInstance)
            self.volume = self.tester.create_volume(azone=self.zone, size=4)
            device_path = instance.attach_volume(self.volume)
            instance.sys("mkfs.ext3 -F " + device_path)
            instance.sys("mount " + device_path + " /mnt")
            ### Write to root fs
            instance.sys("dd if=/dev/zero of=/tmp/test.img count=" +
                         str(file_size_in_mb) + " bs=1M")
            ### Write to volume
            instance.sys("dd if=/dev/zero of=/mnt/test.img count=" +
                         str(file_size_in_mb) + " bs=1M")

        self.tester.sleep(180)
        for instance in self.reservation.instances:
            report_output = self.generate_report("instance", "csv", self.date)
            instance_lines = self.tester.grep(instance.id, report_output)
            for line in instance_lines:
                instance_data = self.parse_instance_line(line)
                #if not re.search( instance.id +",m1.small,1,9,0.2,0,0,0,0,93,200,0.2,0.0,0,1", line):
                if not re.match(instance_data.type, "m1.small"):
                    raise Exception("Failed to find proper output for " +
                                    str(instance) + " type. Received: " +
                                    instance_data.type)
                if not int(instance_data.number) == 1:
                    raise Exception("Failed to find proper output for " +
                                    str(instance) + " number. Received: " +
                                    instance_data.number)
                if not int(instance_data.unit_time) > 2:
                    raise Exception("Failed to find proper output for " +
                                    str(instance) + " unit_time. Received: " +
                                    instance_data.unit_time)
                if not int(instance_data.disk_write) > 1000:
                    raise Exception("Failed to find proper output for " +
                                    str(instance) + " disk_write. Received: " +
                                    instance_data.disk_write)
                if not int(instance_data.disk_time_write) > 200:
                    raise Exception("Failed to find proper output for " +
                                    str(instance) +
                                    " disk_time_write. Received: " +
                                    instance_data.disk_time_write)

    def parse_instance_line(self, line):
        InstanceData = namedtuple(
            'InstanceData',
            'id type number unit_time cpu net_total_in net_total_out '
            'net_extern_in net_extern_out disk_read disk_write disk_iops_read '
            'disk_iops_write disk_time_read disk_time_write')
        values = line.split(",")
        return InstanceData(values[0], values[1], values[2], values[3],
                            values[4], values[5], values[6], values[7],
                            values[8], values[9], values[10], values[11],
                            values[12], values[13], values[14])

    def s3(self):
        self.bucket = self.tester.create_bucket(
            bucket_name="reporting-bucket-" + self.cur_time)
        key_size = 10
        self.tester.debug("Creating random " + str(key_size) + "MB of data")
        rand_string = self.tester.id_generator(size=1024 * 1024 * 10)
        self.tester.upload_object(self.bucket.name,
                                  "reporting-key",
                                  contents=rand_string)
        self.tester.sleep(120)
        report_output = self.generate_report("s3", "csv", self.date)
        bucket_lines = self.tester.grep(self.bucket.name, report_output)
        for line in bucket_lines:
            bucket_data = self.parse_bucket_line(line)
            if not int(bucket_data.size) == 10:
                raise Exception('Failed to find proper size for %s' %
                                str(self.bucket))
            if not int(bucket_data.keys) == 1:
                raise Exception('Failed to find proper number of keys for %s' %
                                str(self.bucket))
            if not int(bucket_data.unit_time) > 16:
                raise Exception(
                    'Failed to find proper amount of usage for %s' %
                    str(self.bucket))

    def parse_bucket_line(self, line):
        BucketData = namedtuple('BucketData', 'name keys size unit_time')
        values = line.split(",")
        return BucketData(values[0], values[1], values[2], values[3])

    def generate_report(self, type, format, end_date):
        return self.clc.sys("source " + self.tester.credpath +
                            "/eucarc && eureport-generate-report -t " +
                            str(type) + " -f " + str(format) + " -e " +
                            str(end_date))

    def modify_property(self, property, value):
        """
        Modify a eucalyptus property through the command line euca-modify-property tool
        property        Property to modify
        value           Value to set it too
        """
        command = "source " + self.tester.credpath + "/eucarc && " + self.tester.eucapath + "/usr/sbin/euca-modify-property -p " + str(
            property) + "=" + str(value)
        if self.clc.found(command, property):
            self.debug("Properly modified property " + property)
        else:
            raise Exception("Setting property " + property + " failed")
Example #33
0
class Euca6559(unittest.TestCase):
    def setUp(self):
        self.conf = "cloud.conf"
        self.tester = Eucaops(config_file=self.conf, password="******")
        self.doAuth()

    def tearDown(self):
        self.tester.cleanup_artifacts()
        self.tester.delete_keypair(self.keypair)
        self.tester.local("rm " + self.keypair.name + ".pem")
        shutil.rmtree(self.tester.credpath)

    def runSysCmd(self, cmd):
        self.source = "source " + self.tester.credpath + "/eucarc && "
        self.out = self.tester.sys(self.source + cmd)

    def doAuth(self):
        self.keypair = self.tester.add_keypair()
        self.group = self.tester.add_group()
        self.tester.authorize_group(self.group)

    def testName(self):
        self.emi = self.tester.get_emi()
        self.new_emi = self.tester.register_manifest(self.emi.location)
        self.tester.deregister_image(self.new_emi);
        self.runSysCmd('euca-describe-images ' + self.new_emi.id);
        ### make sure that the images in the deregistered state are not output to user.
        if  str(self.out).count('deregistered') == 0 :
            self.tester.debug("SUCCESS")
            pass
        else:
            self.fail("FAIL")
Example #34
0
                                               bucket=self.bucket_obj)
        self.assertEqual(
            response.status, 404,
            'Expected response status code to be 404, actual status code is ' +
            str(response.status))

    def tearDown(self):
        self.tester = None


if __name__ == "__main__":
    ### Parse command line arguments and get the path to credentials
    parser = argparse.ArgumentParser(
        description='Unit test to verify fix for EUCA-2782 and EUCA-2241')
    parser.add_argument('--credpath',
                        dest='credpath',
                        required=True,
                        help='Path to folder containing credentials')
    args = parser.parse_args()

    try:
        ### Setup the cloud connection
        eucaops = Eucaops(credpath=args.credpath)
    except Exception, e:
        exit('Failed to establish connection to cloud due to: ' + str(e))

    ### Run the unit test
    suite = unittest.TestLoader().loadTestsFromTestCase(EUCA2782)
    unittest.TextTestRunner(verbosity=2).run(suite)

    eucaops = None
Example #35
0
    def __init__(self):
        self.setuptestcase()
        self.setup_parser()
        self.get_args()
        if not boto.config.has_section('Boto'):
            boto.config.add_section('Boto')
            boto.config.set('Boto', 'num_retries', '1')
            boto.config.set('Boto', 'http_socket_timeout', '20')
        self.tester = Eucaops(config_file=self.args.config_file,
                              password=self.args.password)
        self.tester.ec2.connection.timeout = 30
        self.servman = self.tester.service_manager
        self.instance_timeout = 120
        ### Add and authorize a group for the instance
        self.start_time = str(int(time.time()))
        try:
            self.group = self.tester.add_group(group_name="group-" +
                                               self.start_time)
            self.tester.authorize_group_by_name(group_name=self.group.name)
            self.tester.authorize_group_by_name(group_name=self.group.name,
                                                port=-1,
                                                protocol="icmp")
            ### Generate a keypair for the instance
            self.keypair = self.tester.add_keypair("keypair-" +
                                                   self.start_time)
            self.keypath = os.curdir + "/" + self.keypair.name + ".pem"
            if self.args.emi:
                self.image = self.tester.get_emi(self.args.emi)
            else:
                self.image = self.tester.get_emi(
                    root_device_type="instance-store")
            self.reservation = None
            self.private_addressing = False
            self.bucket_prefix = "buckettestsuite-" + self.start_time + "-"
            self.test_user_id = self.tester.s3.get_canonical_user_id()
            zones = self.tester.ec2.get_all_zones()
            self.zone = random.choice(zones).name

            self.tester.clc = self.tester.service_manager.get_enabled_clc(
            ).machine
            self.version = self.tester.clc.sys(
                "cat " + self.tester.eucapath +
                "/etc/eucalyptus/eucalyptus-version")[0]
            ### Create standing resources that will be checked after all failures
            ### Instance, volume, buckets
            ###
            self.standing_reservation = self.tester.run_instance(
                image=self.image,
                keypair=self.keypair.name,
                group=self.group.name,
                zone=self.zone)
            self.volume = self.tester.create_volume(self.zone)
            self.device = self.standing_reservation.instances[0].attach_volume(
                self.volume)
            for instance in self.standing_reservation.instances:
                instance.sys("echo " + instance.id + " > " + self.device)
            self.standing_bucket_name = "failover-bucket-" + self.start_time
            self.standing_bucket = self.tester.create_bucket(
                self.standing_bucket_name)
            self.standing_key_name = "failover-key-" + self.start_time
            self.standing_key = self.tester.upload_object(
                self.standing_bucket_name, self.standing_key_name)
            self.standing_key = self.tester.get_objects_by_prefix(
                self.standing_bucket_name, self.standing_key_name)
            self.run_instance_params = {
                'image': self.image,
                'keypair': self.keypair.name,
                'group': self.group.name,
                'zone': self.zone,
                'timeout': self.instance_timeout
            }
        except Exception, e:
            self.clean_method()
            raise Exception("Init for testcase failed. Reason: " + str(e))
Example #36
0
class ObjectTestSuite(EutesterTestCase):
    data_size = 1000
    
    def __init__(self):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument("--s3endpoint", default=None)
        self.get_args()
        # Setup basic eutester object
        if self.args.s3endpoint:
            self.tester = S3ops( credpath=self.args.credpath, endpoint=self.args.endpoint)
        else:
            self.tester = Eucaops( credpath=self.args.credpath, config_file=self.args.config, password=self.args.password)
        
        self.bucket_prefix = "eutester-bucket-test-suite-" + str(int(time.time())) + "-"
        self.buckets_used = set()
        random.seed(time.time())
        self.test_bucket_name = self.bucket_prefix + str(random.randint(0,100))
        self.test_bucket = self.tester.create_bucket(self.test_bucket_name)
        self.buckets_used.add(self.test_bucket_name)
        #Create some test data for the objects
        self.test_object_data = ""
        for i in range(0, self.data_size):
            self.test_object_data += chr(random.randint(32,126))            
        print "Generated data for objects: " + self.test_object_data
        
    
    def print_key_info(self, keys=None):
        for key in keys:
            self.tester.info("Key=" + str(key.key) + " -- version= " + str(key.version_id) + " -- eTag= " + str(key.etag)
                             + " -- ACL= " + str(key.get_xml_acl()))
    
    def put_object(self, bucket=None, object_key=None, object_data=None):
        """Puts an object with the specified name and data in the specified bucket"""
        if bucket == None:
            raise Exception("Cannot put object without proper bucket reference")
        
        try :
            key = Key(bucket=bucket,name=object_key)
            key.set_contents_from_string(object_data)                        
            return key.etag
        except Exception as e:
            self.tester.info("Exception occured during 'PUT' of object " + object_key + " into bucket " + bucket.name + ": " + e.message)
            return None
        
     
    def enable_versioning(self, bucket):
        """Enable versioning on the bucket, checking that it is not already enabled and that the operation succeeds."""
        vstatus = bucket.get_versioning_status()
        if vstatus != None and len(vstatus.keys()) > 0 and vstatus['Versioning'] != None and vstatus['Versioning'] != 'Disabled':
            self.tester.info("Versioning status should be null/Disabled, found: " + vstatus['Versioning'])
            return False
        else:
            self.tester.info("Bucket versioning is Disabled")
        
        #Enable versioning
        bucket.configure_versioning(True)
        if bucket.get_versioning_status()['Versioning'] == 'Enabled':
            self.tester.info("Versioning status correctly set to enabled")
            return True
        else:
            self.tester.info("Versioning status not enabled, should be.")
            return False
        return False
    
    def suspend_versioning(self, bucket):
        """Suspend versioning on the bucket, checking that it is previously enabled and that the operation succeeds."""
        if bucket.get_versioning_status()['Versioning'] == 'Enabled':
            self.tester.info("Versioning status correctly set to enabled")
        else:
            self.tester.info("Versioning status not enabled, should be. Can't suspend if not enabled....")
            return False
    
        #Enable versioning
        bucket.configure_versioning(False)
        if bucket.get_versioning_status()['Versioning'] == 'Suspended':
            self.tester.info("Versioning status correctly set to suspended")
            return True
        else:
            self.tester.info("Versioning status not suspended.")
            return False
        return False 
             
    def check_version_listing(self, version_list, total_expected_length):
        """Checks a version listing for both completeness and ordering as well as pagination if required"""
        self.tester.info("Checking bucket version listing. Listing is " + str(len(version_list)) + " entries long")
        if total_expected_length >= 1000:
            assert(len(version_list) == 999)
        else:
            assert(len(version_list) == total_expected_length)
        
        prev_obj = None
        should_fail = None
        for obj in version_list:
            if isinstance(obj,Key):
                self.tester.info("Key: " + obj.name + " -- " + obj.version_id + "--" + obj.last_modified)                
                if prev_obj != None:
                    if self.compare_versions(prev_obj, obj) > 0:
                        should_fail = obj
                prev_obj = obj
            else:
                self.tester.info("Not a key, skipping: " + str(obj))
        return should_fail

    def compare_versions(self, key1, key2):
        """
        Returns -1 if key1 < key2, 0 if equal, and 1 if key1 > key2. 
        Compares names lexicographically, if equal, compares date_modified if versions are different. 
        If version_id and name are equal then key1 = key2
        If an error occurs or something is wrong, returns None
        """
        if key1.name < key2.name:
            #self.debug("Key1: " + key1.name + " is less than " + key2.name)
            return 1
        elif key1.name > key2.name:
            #self.debug("Key1: " + key1.name + " is greater than " + key2.name)
            return -1
        else:
            if key1.version_id == key2.version_id:
                #self.debug("Key1: " + key1.name + " is the same version as " + key2.name)
                return 0
            else:
                if dateutil.parser.parse(key1.last_modified) > dateutil.parser.parse(key2.last_modified):
                    #self.debug("Key1: " + key1.last_modified + " last modified is greater than " + key2.last_modified)
                    return 1
                elif dateutil.parser.parse(key1.last_modified) < dateutil.parser.parse(key2.last_modified):
                    #self.debug("Key1: " + key1.last_modified + " last modified is less than " + key2.last_modified)
                    return -1
        return None
    
    def test_object_basic_ops(self):
        """
        Tests basic operations on objects: simple GET,PUT,HEAD,DELETE.
        
        """
        self.tester.info("Basic Object Operations Test (GET/PUT/HEAD)")
        if self.test_bucket == None:
            self.fail("Error: test_bucket not set, cannot run test")
            
        #Test PUT & GET
        testkey="testkey1-" + str(int(time.time()))
        self.put_object(bucket=self.test_bucket, object_key=testkey, object_data=self.test_object_data)
        
        ret_key = self.test_bucket.get_key(testkey)
        ret_content = ret_key.get_contents_as_string()
        
        if ret_content == self.test_object_data:
            self.tester.info("Set content = get content, put passed")
        else:
            if ret_content != None:
                self.tester.info("Got content: " + ret_content)
            else:
                self.tester.info("No content returned")
            self.tester.info("Expected content: " + self.test_object_data)
            self.fail("Put content not the same as what was returned")
        
        #Test HEAD
        key_meta = self.test_bucket.get_key(testkey)
        if key_meta != ret_key:
            self.tester.info("Something is wrong, the HEAD operation returned different metadata than the GET operation")
        else:
            self.tester.info("HEAD meta = GET meta, all is good")
        
        #Test copy operation (GET w/source headers)
        new_key = "testkey2"
        self.test_bucket.copy_key(new_key, self.test_bucket_name,testkey)
        keylist = self.test_bucket.list()
        counter = 0
        for k in keylist:
            if isinstance(k, Prefix):
                self.tester.info("Prefix: " + "NULL" if k == None else k.name)
            else:
                self.tester.info("Key: " + k.name + " Etag: " + k.etag)
                counter += 1
        if counter != 2:
            self.fail("Expected 2 keys after copy operation, found only: " + len(keylist))
        try:
            ret_key = self.test_bucket.get_key(new_key)
        except:
            self.fail("Could not get object copy")
        if ret_key == None:
            self.fail("Could not get object copy")
            
        if self.test_bucket.get_key(testkey).get_contents_as_string() != ret_key.get_contents_as_string():
            self.fail("Contents of original key and copy don't match")
        else:
            self.tester.info("Copy key contents match original!")
        
        #Test DELETE
        self.test_bucket.delete_key(testkey)
        ret_key = None
        ret_key = self.test_bucket.get_key(testkey)
        if ret_key:
            self.tester.info("Erroneously got: " + ret_key.name)
            raise S3ResponseError(404, "Should have thrown exception for getting a non-existent object")
        self.tester.info("Finishing basic ops test")
               
    def test_object_byte_offset_read(self):
        """Tests fetching specific byte offsets of the object"""
        self.tester.info("Byte-range Offset GET Test")
        self.test_bucket = self.clear_and_rebuild_bucket(self.test_bucket_name)
        testkey = "rangetestkey-" + str(int(time.time()))
        source_bytes = bytearray(self.test_object_data)
        
        #Put the object initially
        self.put_object(bucket=self.test_bucket, object_key=testkey, object_data=self.test_object_data)
        
        #Test range for first 100 bytes of object
        print "Trying start-range object get"
        try:
            data_str = Key(bucket=self.test_bucket,name=testkey).get_contents_as_string(headers={"Range":"bytes=0-99"})
        except:
            self.fail("Failed range object get first 100 bytes")
        
        startrangedata = bytearray(data_str)        
        print "Got: " + startrangedata
        print "Expected: " + str(source_bytes[:100])
        start = 0        
        for i in range(0,100):
            if startrangedata[i-start] != source_bytes[i]:
                print "Byte: " + startrangedata[i] + " differs!"
                self.fail("Start-range Ranged-get failed")
            
        print "Trying mid-object range"   
        try: 
            data_str = Key(bucket=self.test_bucket,name=testkey).get_contents_as_string(headers={"Range":"bytes=500-599"})
        except:
            self.fail("Failed range object get for middle 100 bytes")     
        midrangedata = bytearray(data_str)
        start = 500
        for i in range(start,start+100):
            if midrangedata[i-start] != source_bytes[i]:
                print "Byte: " + midrangedata[i] + "differs!"
                self.fail("Mid-range Ranged-get failed")
        
        print "Trying end-range object get"
        #Test range for last 100 bytes of object
        try:
            data_str = Key(bucket=self.test_bucket,name=testkey).get_contents_as_string(headers={"Range":"bytes=800-899"})
        except:
            self.fail("Failed range object get for last 100 bytes")
            
        endrangedata = bytearray(data_str)
        print "Got: " + str(endrangedata)
        start = 800
        try:
            for i in range(start,start+100):
                if endrangedata[i-start] != source_bytes[i]:
                    print "Byte: " + endrangedata[i] + "differs!"
                    self.fail("End-range Ranged-get failed")
        except Exception as e:
            print "Exception! Received: " + e
        
        print "Range test complete"
        
    def test_object_post(self):
        """Test the POST method for putting objects, requires a pre-signed upload policy and url"""
        self.fail("Test not implemented")
                
    def test_object_large_objects(self):
        """Test operations on large objects (>1MB), but not so large that we must use the multi-part upload interface"""
        self.tester.info("Testing large-ish objects over 1MB in size on bucket" + self.test_bucket_name)
        self.test_bucket = self.clear_and_rebuild_bucket(self.test_bucket_name)
        test_data = ""
        large_obj_size_bytes = 5 * 1024 * 1024 #5MB
        self.tester.info("Generating " + str(large_obj_size_bytes) + " bytes of data")

        #Create some test data
        for i in range(0, large_obj_size_bytes):
            test_data += chr(random.randint(32,126))

        self.tester.info("Uploading object content of size: " + str(large_obj_size_bytes) + " bytes")        
        keyname = "largeobj-" + str(int(time.time()))
        self.put_object(bucket=self.test_bucket, object_key=keyname, object_data=test_data)
        self.tester.info("Done uploading object")

        ret_key = self.test_bucket.get_key(keyname)
        ret_data = ret_key.get_contents_as_string()
        
        if ret_data != test_data:
            self.fail("Fetched data and generated data don't match")
        else:
            self.tester.info("Data matches!")
        
        self.tester.info("Removing large object")
        self.test_bucket.delete_key(ret_key)
        self.tester.info("Complete large object test")
        pass
            
    def test_object_multipart(self):
        """Test the multipart upload interface"""
        self.fail("Feature not implemented")
        
    def test_object_versioning_enabled(self):
        """Tests object versioning for get/put/delete on a versioned bucket"""
        self.tester.info("Testing bucket Versioning-Enabled")
        self.test_bucket = self.clear_and_rebuild_bucket(self.test_bucket_name)
        if not self.enable_versioning(self.test_bucket):
            self.fail("Could not properly enable versioning")
             
        #Create some keys
        keyname = "versionkey-" + str(int(time.time()))
        
        #Multiple versions of the data
        v1data = self.test_object_data + "--version1"
        v2data = self.test_object_data + "--version2"
        v3data = self.test_object_data + "--version3"
        
        #Test sequence: put v1, get v1, put v2, put v3, get v3, delete v3, restore with v1 (copy), put v3 again, delete v2 explicitly
        self.put_object(bucket=self.test_bucket, object_key=keyname, object_data=v1data)
                
        #Get v1
        obj_v1 = self.test_bucket.get_key(keyname)
        self.tester.check_md5(eTag=obj_v1.etag,data=v1data)
        
        self.tester.info("Initial bucket state after object uploads without versioning:")
        self.print_key_info(keys=[obj_v1])
                
        #Put v2 (and get/head to confirm success)
        self.put_object(bucket=self.test_bucket, object_key=keyname,object_data=v2data)
        obj_v2 = self.test_bucket.get_key(keyname)
        self.tester.check_md5(eTag=obj_v2.etag,data=v2data)
        self.print_key_info(keys=[obj_v1, obj_v2])
        
        #Put v3 (and get/head to confirm success)
        self.put_object(bucket=self.test_bucket, object_key=keyname,object_data=v3data)
        obj_v3 = self.test_bucket.get_key(keyname)
        self.tester.check_md5(eTag=obj_v3.etag,data=v3data)
        self.print_key_info(keys=[obj_v1, obj_v2, obj_v3])
        
        #Get a specific version, v1
        v1_return = self.test_bucket.get_key(key_name=keyname,version_id=obj_v1.version_id)
        self.print_key_info(keys=[v1_return])
        
        #Delete current latest version (v3)
        self.test_bucket.delete_key(keyname)

        del_obj = self.test_bucket.get_key(keyname)
        if del_obj:
            self.tester.info("Erroneously got: " + del_obj.name)
            raise S3ResponseError(404, "Should have thrown this exception for getting a non-existent object")
        
        #Restore v1 using copy
        try:
            self.test_bucket.copy_key(new_key_name=obj_v1.key,src_bucket_name=self.test_bucket_name,src_key_name=keyname,src_version_id=obj_v1.version_id)
        except S3ResponseError as e:
            self.fail("Failed to restore key from previous version using copy got error: " + str(e.status))
            
        restored_obj = self.test_bucket.get_key(keyname)
        self.tester.check_md5(eTag=restored_obj.etag,data=v1data)
        self.print_key_info(keys=[restored_obj])
        
        #Put v3 again
        self.put_object(bucket=self.test_bucket, object_key=keyname,object_data=v3data)
        self.tester.check_md5(eTag=obj_v3.etag,data=v3data)
        self.print_key_info([self.test_bucket.get_key(keyname)])

        #Delete v2 explicitly
        self.test_bucket.delete_key(key_name=obj_v2.key,version_id=obj_v2.version_id)
        del_obj = self.test_bucket.get_key(keyname,version_id=obj_v2.version_id)
        if del_obj:
            raise S3ResponseError("Should have gotten 404 not-found error, but got: " + del_obj.key + " instead",404)

        #Show what's on top
        top_obj = self.test_bucket.get_key(keyname)
        self.print_key_info([top_obj])
        self.tester.check_md5(eTag=top_obj.etag,data=v3data)
        
        self.tester.info("Finished the versioning enabled test. Success!!")

    def clear_and_rebuild_bucket(self, bucket_name):
        self.tester.clear_bucket(bucket_name)
        return self.tester.create_bucket(bucket_name)

    def test_object_versionlisting(self):
        """
        Tests object version listing from a bucket
        """
        version_max = 3
        keyrange = 20
        self.tester.info("Testing listing versions in a bucket and pagination using " + str(keyrange) + " keys with " + str(version_max) + " versions per key")
        self.test_bucket = self.clear_and_rebuild_bucket(self.test_bucket_name)
        if not self.enable_versioning(self.test_bucket):
            self.fail("Could not enable versioning properly. Failing")
        
        key = "testkey-" + str(int(time.time()))
        keys = [ key + str(k) for k in range(0,keyrange)]        
        contents = [ self.test_object_data + "--v" + str(v) for v in range(0,version_max)]        

        try:
            for keyname in keys:
                #Put version_max versions of each key
                for v in range(0,version_max):
                    self.tester.info("Putting: " + keyname + " version " + str(v))
                    self.test_bucket.new_key(keyname).set_contents_from_string(contents[v])
        except S3ResponseError as e:
            self.fail("Failed putting object versions for test: " + str(e.status))
        listing = self.test_bucket.get_all_versions()
        self.tester.info("Bucket version listing is " + str(len(listing)) + " entries long")
        if keyrange * version_max >= 1000:
            if not len(listing) == 999:
                self.test_bucket.configure_versioning(False)
                self.tester.debug(str(listing))
                raise Exception("Bucket version listing did not limit the response to 999. Instead: " + str(len(listing)))
        else:
            if not len(listing) == keyrange * version_max:
                self.test_bucket.configure_versioning(False)
                self.tester.debug(str(listing))
                raise Exception("Bucket version listing did not equal the number uploaded. Instead: " + str(len(listing)))
        
        prev_obj = None
        for obj in listing:
            if isinstance(obj,Key):
                self.tester.info("Key: " + obj.name + " -- " + obj.version_id + "--" + obj.last_modified)                
                if prev_obj != None:
                    if self.compare_versions(prev_obj, obj) <= 0:
                        raise Exception("Version listing not sorted correctly, offending key: " + obj.name + " version: " + obj.version_id + " date: " + obj.last_modified)
                prev_obj = obj
            else:
                self.tester.info("Not a key, skipping: " + str(obj))
    
    def test_object_versioning_suspended(self):
        """Tests object versioning on a suspended bucket, a more complicated test than the Enabled test"""
        self.tester.info("Testing bucket Versioning-Suspended")
        self.test_bucket = self.clear_and_rebuild_bucket(self.test_bucket_name)
        #Create some keys
        keyname1 = "versionkey1-" + str(int(time.time()))
        keyname2 = "versionkey2-" + str(int(time.time()))
        keyname3 = "versionkey3-" + str(int(time.time()))
        keyname4 = "versionkey4-" + str(int(time.time()))
        keyname5 = "versionkey5-" + str(int(time.time()))
        v1data = self.test_object_data + "--version1"
        v2data = self.test_object_data + "--version2"
        v3data = self.test_object_data + "--version3"
        
        vstatus = self.test_bucket.get_versioning_status()
        if vstatus:
            self.fail("Versioning status should be null/Disabled but was: " + str(vstatus))
        else:
            self.tester.info("Bucket versioning is Disabled")
        
        self.put_object(bucket=self.test_bucket, object_key=keyname1, object_data=v1data)
        self.put_object(bucket=self.test_bucket, object_key=keyname2, object_data=v1data)
        self.put_object(bucket=self.test_bucket, object_key=keyname3, object_data=v1data)
        self.put_object(bucket=self.test_bucket, object_key=keyname4, object_data=v1data)
        self.put_object(bucket=self.test_bucket, object_key=keyname5, object_data=v1data)
                    
        key1 = self.test_bucket.get_key(keyname1)        
        key2 = self.test_bucket.get_key(keyname2)        
        key3 = self.test_bucket.get_key(keyname3)        
        key4 = self.test_bucket.get_key(keyname4)        
        key5 = self.test_bucket.get_key(keyname5)

        self.tester.info("Initial bucket state after object uploads without versioning:")
        self.print_key_info(keys=[key1,key2,key3,key4,key5])
        
        
        
        #Enable versioning
        self.test_bucket.configure_versioning(True)
        if self.test_bucket.get_versioning_status():
            self.tester.info("Versioning status correctly set to enabled")
        else:
            self.tester.info("Versionign status not enabled, should be.")            
        
        #Update a subset of the keys
        key1_etag2=self.put_object(bucket=self.test_bucket, object_key=keyname1,object_data=v2data)
        key2_etag2=self.put_object(bucket=self.test_bucket, object_key=keyname2,object_data=v2data)
        
        key3_etag2=self.put_object(bucket=self.test_bucket, object_key=keyname3,object_data=v2data)
        key3_etag3=self.put_object(bucket=self.test_bucket, object_key=keyname3,object_data=v3data)
        
        #Delete a key
        self.test_bucket.delete_key(keyname5)

        #Suspend versioning
        self.test_bucket.configure_versioning(False)
        
        #Get latest of each key
        key1=self.test_bucket.get_key(keyname1)
        key2=self.test_bucket.get_key(keyname2)
        key3=self.test_bucket.get_key(keyname3)
        key4=self.test_bucket.get_key(keyname4)
        key5=self.test_bucket.get_key(keyname5)
        
        #Delete a key
        
        #Add a key
        
        #Add same key again
        
        #Fetch each key
    
    def test_object_acl(self):
        """Tests object acl get/set and manipulation"""
        self.fail("Test not implemented")
        
        #TODO: test custom and canned acls that are both valid an invalid
        
    def test_object_torrent(self):
        """Tests object torrents"""
        self.fail("Feature not implemented yet")

    
    def clean_method(self):
        '''This is the teardown method'''
        #Delete the testing bucket if it is left-over
        self.tester.info('Deleting the buckets used for testing')
        for bucket in self.buckets_used:
            try:
                self.tester.info('Checking bucket ' + bucket + ' for possible cleaning/delete')
                if self.tester.s3.bucket_exists(bucket):
                    self.tester.info('Found bucket exists, cleaning it')
                    self.tester.clear_bucket(bucket)
                    self.buckets_used.remove(bucket)
                else:
                    self.tester.info('Bucket ' + bucket + ' not found, skipping')
            except:
                self.tester.info('Exception checking bucket ' + bucket)

        return
Example #37
0
 def __init__(self, 
              #setup eutester and test environment...
              tester=None, 
              config_file=None, 
              cred_path=None,
              password=None, 
              credpath=None, 
              eof=True,
              #Information on where to do image bundle work, and related timeouts
              destpath=None,  
              time_per_gig = 300,
              inter_bundle_timeout=120, 
              upload_timeout=0,
              work_component=None,
              component_credpath=None,
              bucketname = None,
              #Test env resources...
              group = None,
              testvolumes = [],
              testvolcount = 2,
              keypair=None, 
              zone = None,
              url=None,
              user_data=None,
              emi=None,
              private_addressing=False,
              instance_password = None,
              instance_keypath = None,
              vmtype='m1.xlarge',
              emi_location=None,
              image_path=None, #note this must be available on the work_component
              instance=None,
              win_proxy_hostname = None, 
              win_proxy_username = '******',
              win_proxy_password = None, 
              win_proxy_keypath = None,
              authports=['tcp:3389','tcp:80','tcp:443', 'tcp:5985', 'tcp:5986']
              ):
     if tester is None:
         self.tester = Eucaops( config_file=config_file,password=password,credpath=credpath)
     else:
         self.tester = tester
     self.tester.exit_on_fail = eof
     self.instance = instance
     if self.instance:
         self.instance = self.tester.get_instances(idstring=str(instance))[0]
     self.instance_keypath = instance_keypath
     self.destpath = destpath or '/tmp'
     self.bucketname = bucketname
     self.component = work_component 
     self.component_credpath = component_credpath
     self.time_per_gig = time_per_gig
     self.credpath=credpath or self.tester.credpath
     self.url = url
     self.upload_timeout = upload_timeout
     self.inter_bundle_timeout = inter_bundle_timeout
     self.iu = ImageUtils(tester=self.tester, destpath=self.destpath, time_per_gig=self.time_per_gig, work_component=self.component)
     self.group = group 
     self.keypair = keypair
     self.zonelist = []
     self.emi = self.tester.get_emi(emi)
     self.image_path = image_path
     self.emi_location = emi_location
     if zone is not None:
         self.zonelist.append(zone)
     self.testvolcount = testvolcount
     self.testvolumes = testvolumes
     self.authports=authports
     self.instance_password = instance_password
     self.vmtype= vmtype 
     self.user_data = user_data
     self.private_addressing = private_addressing
     #timeout for run instance command/test
     self.run_timeout=780 
     #setup zone list
     self.setupWindowsZones()
     #setup windows proxy 
     self.win_proxy_hostname = win_proxy_hostname
     self.proxy = None
     if win_proxy_hostname is not None:
         self.setup_proxy(win_proxy_hostname,
                          proxy_keypath = win_proxy_keypath,
                          proxy_username = win_proxy_username,
                          proxy_password = win_proxy_password,
                          debugmethod = lambda msg: self.debug(msg, traceback=2)
                          )
     self.setup_test_env()
     if self.instance and self.proxy:
             self.update_proxy_instance_data()
Example #38
0
class CloudFormations(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        if self.args.region:
            self.tester = CFNops(credpath=self.args.credpath,
                                 region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath,
                                  config_file=self.args.config,
                                  password=self.args.password)
        self.group = self.tester.add_group(group_name="group-" +
                                           str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name)
        self.tester.authorize_group_by_name(group_name=self.group.name,
                                            port=-1,
                                            protocol="icmp")
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)

    def InstanceVolumeTemplate(self):
        self.stack_name = "volumeTest{0}".format(int(time.time()))
        template = Template()
        keyname_param = template.add_parameter(
            Parameter(
                "KeyName",
                Description="Name of an existing EC2 KeyPair "
                "to enable SSH access to the instance",
                Type="String",
            ))
        template.add_mapping('RegionMap',
                             {"": {
                                 "AMI": self.tester.get_emi().id
                             }})
        for i in xrange(2):
            ec2_instance = template.add_resource(
                ec2.Instance("Instance{0}".format(i),
                             ImageId=FindInMap("RegionMap", Ref("AWS::Region"),
                                               "AMI"),
                             InstanceType="t1.micro",
                             KeyName=Ref(keyname_param),
                             SecurityGroups=[self.group.name],
                             UserData=Base64("80")))
            vol = template.add_resource(
                ec2.Volume("Volume{0}".format(i),
                           Size="8",
                           AvailabilityZone=GetAtt("Instance{0}".format(i),
                                                   "AvailabilityZone")))
            mount = template.add_resource(
                ec2.VolumeAttachment("MountPt{0}".format(i),
                                     InstanceId=Ref("Instance{0}".format(i)),
                                     VolumeId=Ref("Volume{0}".format(i)),
                                     Device="/dev/vdc"))
        stack = self.tester.create_stack(self.stack_name,
                                         template.to_json(),
                                         parameters=[("KeyName",
                                                      self.keypair.name)])

        def stack_completed():
            return self.tester.cloudformation.describe_stacks(
                self.stack_name).status == "CREATE_COMPLETE"

        self.tester.wait_for_result(stack_completed, True, timeout=600)
        self.tester.delete_stack(self.stack_name)

    def clean_method(self):
        self.tester.cleanup_artifacts()
Example #39
0
class CloudWatchBasics(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument(
            '--clean_on_exit',
            action='store_true',
            default=True,
            help=
            'Boolean, used to flag whether to run clean up method after running test list)'
        )
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)

        self.get_args()
        ### Setup basic eutester object
        if self.args.region:
            self.tester = CWops(credpath=self.args.credpath,
                                region=self.args.region)
        else:
            self.tester = Eucaops(config_file=self.args.config,
                                  password=self.args.password,
                                  credpath=self.args.credpath)
        self.start_time = str(int(time.time()))
        self.zone = self.tester.get_zones()
        self.namespace = 'Namespace-' + self.start_time
        self.keypair = self.tester.add_keypair()
        self.group = self.tester.add_group()
        ### Setup AutoScaling
        self.setUpAutoscaling()
        ### Create Dimensions used in tests
        self.instanceDimension = newDimension('InstanceId', self.instanceid)
        self.volumeDimension = newDimension('VolumeId', self.volume.id)
        self.autoScalingDimension = newDimension('AutoScalingGroupName',
                                                 self.auto_scaling_group_name)
        ### Setup Alarms
        self.setUpAlarms()
        ### Wait for metrics to populate, timeout 30 minute
        self.tester.wait_for_result(self.IsMetricsListPopulated,
                                    result=True,
                                    timeout=1800)

    def clean_method(self):
        self.cleanUpAutoscaling()
        self.tester.cleanup_artifacts()
        self.tester.delete_keypair(self.keypair)
        pass

    def get_time_window(self, end=None, **kwargs):
        if not end:
            end = datetime.datetime.utcnow()
        start = end - datetime.timedelta(**kwargs)
        return (start, end)

    def print_timeseries_for_graphite(self, timeseries):
        for datapoint in timeseries:
            print 'graph.Namespace-1361426618 ' + str(int(datapoint['Average'])) + ' ' + \
                  str((datapoint['Timestamp'] - datetime.datetime(1970,1,1)).total_seconds())

    def PutDataGetStats(self):
        assert self.testAwsReservedNamspaces()
        seconds_to_put_data = 120
        metric_data = 1
        time_string = str(int(time.time()))
        metric_name = "Metric-" + time_string
        incrementing = True
        while datetime.datetime.now().second != 0:
            self.tester.debug("Waiting for minute edge")
            self.tester.sleep(1)
        start = datetime.datetime.utcnow() - datetime.timedelta(
            seconds=seconds_to_put_data)
        for i in xrange(seconds_to_put_data):
            timestamp = start + datetime.timedelta(seconds=i)
            self.tester.debug(
                "Adding metric: {metric} to namespace: {namespace} with value {value} at {timestamp}"
                .format(metric=metric_name,
                        namespace=self.namespace,
                        value=metric_data,
                        timestamp=timestamp))
            self.tester.cw.put_metric_data(self.namespace, [metric_name],
                                           [metric_data],
                                           timestamp=timestamp)
            if metric_data == 600 or metric_data == 0:
                incrementing = not incrementing
            if incrementing:
                metric_data += 1
            else:
                metric_data -= 1
        end = start + datetime.timedelta(seconds=seconds_to_put_data)
        self.tester.sleep(60)
        metric = self.tester.cw.list_metrics(namespace=self.namespace)[0]
        assert isinstance(metric, Metric)
        stats_array = metric.query(
            start_time=start,
            end_time=end,
            statistics=['Average', 'Sum', 'Maximum', 'Minimum', 'SampleCount'])
        assert len(stats_array) == 2
        if stats_array[0]['Minimum'] == 1:
            first_sample = stats_array[0]
            second_sample = stats_array[1]
        else:
            second_sample = stats_array[0]
            first_sample = stats_array[1]
        print stats_array

        ##Check sample 1
        assert first_sample['Maximum'] <= 60 and first_sample['Minimum'] > 0
        assert first_sample['Average'] < 34 and first_sample['Average'] > 26
        assert first_sample['Sum'] < 1900 and first_sample['Sum'] > 1500
        assert first_sample['SampleCount'] > 50
        ##Check sample 2
        assert second_sample['Maximum'] <= 120 and second_sample['Minimum'] > 50
        assert second_sample['Average'] < 95 and second_sample['Average'] > 80
        assert second_sample['Sum'] < 6100 and second_sample['Sum'] > 4600
        assert second_sample['SampleCount'] > 50

        assert first_sample['Average'] < second_sample['Average']
        assert first_sample['Sum'] < second_sample['Sum']
        assert first_sample['Maximum'] < second_sample['Maximum']
        assert first_sample['Minimum'] < second_sample['Minimum']

    def ListMetrics(self, metricNames, dimension):
        self.debug('Get Metric list')
        metricList = self.tester.list_metrics(dimensions=dimension)
        self.debug('Checking to see if list is populated at all.')
        assert len(metricList) > 0
        self.debug('Make sure dimensions are listed.')
        found = False
        for metric in metricList:
            self.debug(metric.dimensions)
            if str(metric.dimensions).count(dimension[dimension.keys().pop()]):
                self.debug('Dimension ' + dimension[dimension.keys().pop()])
                found = True
                break
        assert found
        self.debug(
            'Checking to see if we get all the expected instance metrics.')
        for metric in metricNames:
            assert str(metricList).count(metric['name']) > 0
            self.debug('Metric ' + metric['name'])
        pass

    def checkMetricFilters(self):
        self.debug('Check list_metrics filtering parameters')
        metricList = self.tester.list_metrics(namespace='AWS/EC2')
        assert len(metricList) > 0
        metricList = self.tester.list_metrics(namespace='AWS/EBS')
        assert len(metricList) > 0
        metricList = self.tester.list_metrics(
            namespace='NonExistent-NameSpace')
        assert len(metricList) == 0
        metricList = self.tester.list_metrics(metric_name='CPUUtilization')
        assert len(metricList) > 0
        metricList = self.tester.list_metrics(
            metric_name='NonExistent-Metric-Name')
        assert len(metricList) == 0
        metricList = self.tester.list_metrics(
            dimensions=self.instanceDimension)
        assert len(metricList) > 0
        metricList = self.tester.list_metrics(
            dimensions=newDimension('InstanceId', 'NonExistent-InstanceId'))
        assert len(metricList) == 0
        metricList = self.tester.list_metrics(dimensions=self.volumeDimension)
        assert len(metricList) > 0
        metricList = self.tester.list_metrics(
            dimensions=newDimension('VolumeId', 'NonExistent-VolumeId'))
        assert len(metricList) == 0
        metricList = self.tester.list_metrics(
            dimensions=newDimension('ImageId', self.image.id))
        assert len(metricList) > 0
        metricList = self.tester.list_metrics(
            dimensions=newDimension('ImageId', 'NonExistent-imageId'))
        assert len(metricList) == 0
        metricList = self.tester.list_metrics(
            dimensions=newDimension('InstanceType', self.instance_type))
        assert len(metricList) > 0
        metricList = self.tester.list_metrics(dimensions=newDimension(
            'InstanceType', 'NonExistent-InstanceType'))
        assert len(metricList) == 0
        metricList = self.tester.list_metrics(
            dimensions=self.autoScalingDimension)
        assert len(metricList) > 0
        metricList = self.tester.list_metrics(dimensions=newDimension(
            'AutoScalingGroupName', 'NonExistent-AutoScalingGroupName'))
        assert len(metricList) == 0
        metricList = self.tester.list_metrics(dimensions=self.volumeDimension)
        assert len(metricList) > 0
        metricList = self.tester.list_metrics(
            dimensions=newDimension('VolumeId', 'NonExistent-VolumeId'))
        assert len(metricList) == 0
        pass

    def IsMetricsListPopulated(self):
        end = datetime.datetime.utcnow()
        start = end - datetime.timedelta(minutes=20)
        metrics1 = self.tester.cw.get_metric_statistics(
            60,
            start,
            end,
            'CPUUtilization',
            'AWS/EC2',
            'Average',
            dimensions=self.instanceDimension,
            unit='Percent')
        metrics2 = self.tester.cw.get_metric_statistics(
            60,
            start,
            end,
            'VolumeReadBytes',
            'AWS/EBS',
            'Average',
            dimensions=self.volumeDimension,
            unit='Bytes')
        if len(metrics1) > 0 and len(metrics2) > 0:
            return True
        else:
            return False

    def GetMetricStatistics(self, metricNames, namespace, dimension):
        period = 60
        end = datetime.datetime.utcnow()
        start = end - datetime.timedelta(minutes=20)
        stats = self.tester.get_stats_array()
        ###Check to make sure we are getting all namespace metrics and statistics
        for i in range(len(metricNames)):
            values = []
            for j in range(len(stats)):
                metricName = metricNames[i]['name']
                statisticName = stats[j]
                unitType = metricNames[i]['unit']
                metrics = self.tester.get_metric_statistics(
                    period,
                    start,
                    end,
                    metricName,
                    namespace,
                    statisticName,
                    dimensions=dimension,
                    unit=unitType)
                ### This assures we are getting all statistics for all dimension metrics.
                assert int(len(metrics)) > 0
                statisticValue = str(metrics[0][statisticName])
                self.debug(metricName + ' : ' + statisticName + '=' +
                           statisticValue + ' ' + unitType)
                values.append(statisticValue)
        self.tester.validateStats(values)

    def setUpAutoscaling(self):
        ### setup autoscaling variables:s
        self.debug('Setting up AutoScaling, starting 1 instance')
        self.instance_type = 'm1.small'
        self.image = self.tester.get_emi(root_device_type='instance-store')
        self.launch_config_name = 'ASConfig'
        self.auto_scaling_group_name = 'ASGroup'
        self.exact = 'ExactCapacity'
        self.change = 'ChangeInCapacity'
        self.percent = 'PercentChangeInCapacity'
        self.cleanUpAutoscaling()
        diskWrite = 'while [ 1 ];do dd if=/dev/zero of=/root/testFile bs=1M count=1; done &'
        diskRead = 'while [ 1 ];do dd if=/root/testFile of=/dev/null bs=1M count=1; done &'
        ### create launch configuration
        self.tester.create_launch_config(name=self.launch_config_name,
                                         image_id=self.image.id,
                                         instance_type=self.instance_type,
                                         key_name=self.keypair.name,
                                         security_groups=[self.group.name],
                                         instance_monitoring=True,
                                         user_data=diskWrite + ' ' + diskRead)
        ### create auto scale group
        self.tester.create_as_group(group_name=self.auto_scaling_group_name,
                                    availability_zones=self.zone,
                                    launch_config=self.launch_config_name,
                                    min_size=0,
                                    max_size=5,
                                    desired_capacity=1)
        ### create auto scale policys
        self.tester.create_as_policy(name=self.exact,
                                     adjustment_type=self.exact,
                                     scaling_adjustment=0,
                                     as_name=self.auto_scaling_group_name,
                                     cooldown=0)

        self.tester.create_as_policy(name=self.change,
                                     adjustment_type=self.change,
                                     scaling_adjustment=1,
                                     as_name=self.auto_scaling_group_name,
                                     cooldown=0)

        self.tester.create_as_policy(name=self.percent,
                                     adjustment_type=self.percent,
                                     scaling_adjustment=-50,
                                     as_name=self.auto_scaling_group_name,
                                     cooldown=0)

        ## Wait for the instance to go to running state.
        self.tester.wait_for_result(self.tester.wait_for_instances,
                                    True,
                                    timeout=600,
                                    group_name=self.auto_scaling_group_name)
        self.instanceid = self.tester.get_last_instance_id()
        instance_list = self.tester.get_instances(idstring=self.instanceid)
        self.instance = instance_list.pop()
        self.debug('ASG is now setup.')
        ### Create and attach a volume
        self.volume = self.tester.create_volume(self.zone.pop())
        self.tester.attach_volume(self.instance, self.volume, '/dev/sdf')
        ### Get the newly created policies.
        self.policy_exact = self.tester.autoscale.get_all_policies(
            policy_names=[self.exact])
        self.policy_change = self.tester.autoscale.get_all_policies(
            policy_names=[self.change])
        self.policy_percent = self.tester.autoscale.get_all_policies(
            policy_names=[self.percent])
        self.debug('AutoScaling setup Complete')

    def cleanUpAutoscaling(self):
        self.tester.delete_all_alarms()
        self.tester.delete_all_policies()
        self.tester.delete_as_group(name=self.auto_scaling_group_name,
                                    force=True)
        self.tester.delete_launch_config(self.launch_config_name)

    def isInService(self):
        group = self.tester.describe_as_group(
            name=self.auto_scaling_group_name)
        allInService = True
        for instance in group.instances:
            if not str(instance.lifecycle_state).endswith('InService'):
                allInService = False
                break
        return allInService

    def setUpAlarms(self):
        metric = 'CPUUtilization'
        comparison = '>'
        threshold = 0
        period = 60
        evaluation_periods = 1
        statistic = 'Average'
        ### This alarm sets the number of running instances to exactly 0
        alarm_exact = self.tester.metric_alarm(
            'exact',
            metric,
            comparison,
            threshold,
            period,
            evaluation_periods,
            statistic,
            description='TEST',
            namespace='AWS/EC2',
            dimensions=self.instanceDimension,
            alarm_actions=self.policy_exact.pop().policy_arn)
        ### This alarm sets the number of running instances to + 1
        alarm_change = self.tester.metric_alarm(
            'change',
            metric,
            comparison,
            threshold,
            period,
            evaluation_periods,
            statistic,
            description='TEST',
            namespace='AWS/EC2',
            dimensions=self.instanceDimension,
            alarm_actions=self.policy_change.pop().policy_arn)
        ### This alarm sets the number of running instances to -50%
        alarm_percent = self.tester.metric_alarm(
            'percent',
            metric,
            comparison,
            threshold,
            period,
            evaluation_periods,
            statistic,
            description='TEST',
            namespace='AWS/EC2',
            dimensions=self.instanceDimension,
            alarm_actions=self.policy_percent.pop().policy_arn)
        ### put all the alarms
        self.tester.put_metric_alarm(alarm_change)
        self.tester.put_metric_alarm(alarm_percent)
        self.tester.put_metric_alarm(alarm_exact)

    def testDesribeAlarms(self):
        self.debug(self.tester.describe_alarms())
        assert len(self.tester.describe_alarms()) >= 3
        ### test describe_alarms_for_metric for created alarms
        assert len(
            self.tester.describe_alarms_for_metric(
                'CPUUtilization', 'AWS/EC2',
                dimensions=self.instanceDimension)) == 3
        ### There are not be any alarms created for 'DiskReadOps'
        assert len(
            self.tester.describe_alarms_for_metric(
                'DiskReadOps', 'AWS/EC2',
                dimensions=self.instanceDimension)) == 0
        ### test describe_alarm_history
        self.debug(self.tester.describe_alarm_history())
        assert len(self.tester.describe_alarm_history()) >= 3
        pass

    def testAlarms(self):
        ### The number of running instances should equal the desired_capacity for the auto_scaling_group = (1)
        group = self.tester.describe_as_group(
            name=self.auto_scaling_group_name)
        assert len(group.instances) == 1
        ### The number of running instances should still be 1 with 'exact' disabled
        self.tester.disable_alarm_actions('exact')
        self.tester.set_alarm_state('exact')
        self.tester.sleep(15)
        group = self.tester.describe_as_group(
            name=self.auto_scaling_group_name)
        assert len(group.instances) == 1
        self.tester.enable_alarm_actions('exact')
        self.debug('The number of running ' + self.auto_scaling_group_name +
                   ' instances = 1')
        ### The number of running instances should equal the desired_capacity + scaling_adjustment = (2)
        self.tester.set_alarm_state('change')
        self.tester.sleep(15)
        self.tester.wait_for_result(self.isInService, result=True, timeout=240)
        group = self.tester.describe_as_group(
            name=self.auto_scaling_group_name)
        self.debug(len(group.instances))
        assert len(group.instances) == 2
        self.debug('Success the number of running ' +
                   self.auto_scaling_group_name + ' instances changed to 2')
        ### The number of running instances should equal the total from the previous scaling_adjustment (2) - 50% = (1)
        self.tester.set_alarm_state('percent')
        self.tester.sleep(15)
        group = self.tester.describe_as_group(
            name=self.auto_scaling_group_name)
        assert len(group.instances) == 1
        self.debug('Success the number of running ' +
                   self.auto_scaling_group_name +
                   ' instances decreased by 50%')
        ### This should terminate all instances in the auto_scaling_group.
        self.tester.set_alarm_state('exact')
        self.tester.sleep(15)
        group = self.tester.describe_as_group(
            name=self.auto_scaling_group_name)
        assert group.instances == None
        self.debug('Success the number of running ' +
                   self.auto_scaling_group_name + ' instances is exactly 0')
        pass

    def testAwsReservedNamspaces(self):
        try:
            self.tester.put_metric_data('AWS/AnyName', 'TestMetricName', 1)
        except Exception, e:
            if str(e).count(
                    'The value AWS/ for parameter Namespace is invalid.'):
                self.tester.debug(
                    'testAwsReservedNamspaces generated expected InvalidParameterValue error.'
                )
                return True
        self.tester.debug(
            'testAwsReservedNamspaces did not throw expected InvalidParameterValue error.'
        )
        return False
Example #40
0
class MigrationTest(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.parser.add_argument('--imgurl',
                                 help="BFEBS Image to splat down",
                                 default=None)
        self.get_args()
        self.tester = Eucaops(config_file=self.args.config,
                              password=self.args.password)
        self.numberOfNodes = self.tester.service_manager.get_all_node_controllers(
        )
        if len(self.numberOfNodes) < 2:
            exit("Not enough NCs to test instance migration.")

        self.group = self.tester.add_group(group_name="group-" +
                                           str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name)
        self.tester.authorize_group_by_name(group_name=self.group.name,
                                            port=-1,
                                            protocol="icmp")

        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)

        self.image = self.args.emi
        if not self.image:
            self.image = self.tester.get_emi(root_device_type="instance-store")
        self.numberOfResources = 3
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name

        try:
            self.tester.get_emi(root_device_type="ebs")
        except:
            bfebs = self.do_with_args(BFEBSBasics)
            bfebs.RegisterImage()

    def clean_method(self):
        self.tester.cleanup_artifacts()

    def MigrationBasic(self, volume=None):
        enabled_clc = self.tester.service_manager.get_enabled_clc().machine
        self.reservation = self.tester.run_instance(
            self.image,
            username=self.args.instance_user,
            keypair=self.keypair.name,
            group=self.group.name,
            zone=self.zone)
        instance = self.reservation.instances[0]
        assert isinstance(instance, EuInstance)
        volume_device = None
        if volume is not None:
            volume_device = instance.attach_euvolume(volume)

        self.tester.service_manager.populate_nodes()
        source_nc = self.tester.service_manager.get_all_node_controllers(
            instance_id=instance.id)[0]
        enabled_clc.sys("source " + self.tester.credpath + "/eucarc &&" +
                        self.tester.eucapath +
                        "/usr/sbin/euca-migrate-instances -i " + instance.id)

        def wait_for_new_nc():
            self.tester.service_manager.populate_nodes()
            destination_nc = self.tester.service_manager.get_all_node_controllers(
                instance_id=instance.id)[0]
            return source_nc.hostname == destination_nc.hostname

        self.tester.wait_for_result(wait_for_new_nc,
                                    False,
                                    timeout=600,
                                    poll_wait=60)
        self.assertTrue(self.tester.ping(instance.public_dns_name),
                        'Could not ping instance')

        if volume_device:
            instance.sys("ls " + volume_device, code=0)

        destination_nc = self.tester.service_manager.get_all_node_controllers(
            instance_id=instance.id)[0]
        if destination_nc.machine.distro.name is not "vmware":
            destination_nc.machine.sys("virsh list | grep " + instance.id,
                                       code=0)
        else:
            destination_nc.machine.sys("esxcli vm process list | grep " +
                                       instance.id,
                                       code=0)

        self.tester.terminate_instances(reservation=self.reservation)
        if volume is not None:
            self.tester.delete_volume(volume)

    def MigrationInstanceStoreWithVol(self):
        volume = self.tester.create_volume(zone=self.zone)
        assert isinstance(volume, EuVolume)
        self.MigrationBasic(volume)

    def MigrationBasicEBSBacked(self, volume=None):
        self.image = self.tester.get_emi(root_device_type="ebs")
        self.MigrationBasic(volume)

    def MigrationBasicEBSBackedWithVol(self):
        volume = self.tester.create_volume(zone=self.zone)
        assert isinstance(volume, EuVolume)
        self.MigrationBasicEBSBacked(volume)

    def MigrateToDest(self):
        enabled_clc = self.tester.service_manager.get_enabled_clc().machine
        self.reservation = self.tester.run_instance(
            self.image,
            username=self.args.instance_user,
            keypair=self.keypair.name,
            group=self.group.name,
            zone=self.zone)
        instance = self.reservation.instances[0]
        self.tester.service_manager.populate_nodes()
        self.source_nc = self.tester.service_manager.get_all_node_controllers(
            instance_id=instance.id)[0]

        all_nc = self.tester.service_manager.get_all_node_controllers()
        self.destination_nc = None

        for nc in all_nc:
            if nc.machine.hostname != self.source_nc.machine.hostname:
                self.destination_nc = nc
                enabled_clc.sys("source " + self.tester.credpath +
                                "/eucarc && " + self.tester.eucapath +
                                "/usr/sbin/euca-migrate-instances -i " +
                                instance.id + " --dest " +
                                self.destination_nc.machine.hostname)

                def wait_for_new_nc():
                    self.tester.service_manager.populate_nodes()
                    self.instance_node = self.tester.service_manager.get_all_node_controllers(
                        instance_id=instance.id)[0]
                    return self.instance_node.hostname == self.destination_nc.hostname

                self.tester.wait_for_result(wait_for_new_nc,
                                            True,
                                            timeout=600,
                                            poll_wait=60)
                self.assertTrue(self.tester.ping(instance.public_dns_name),
                                'Could not ping instance')

        # migrate the instance to it's original source node
        self.destination_nc = self.source_nc
        enabled_clc.sys("source " + self.tester.credpath + "/eucarc && " +
                        self.tester.eucapath +
                        "/usr/sbin/euca-migrate-instances -i " + instance.id +
                        " --dest " + self.destination_nc.machine.hostname)

        self.tester.wait_for_result(wait_for_new_nc,
                                    True,
                                    timeout=600,
                                    poll_wait=60)
        self.assertTrue(self.tester.ping(instance.public_dns_name),
                        'Could not ping instance')

        self.tester.terminate_instances(reservation=self.reservation)

    def MigrationToDestEBSBacked(self):
        self.image = self.tester.get_emi(root_device_type="ebs")
        self.MigrateToDest()

    def EvacuateNC(self, volume_list=[]):
        instance_list = []
        enabled_clc = self.tester.service_manager.get_enabled_clc().machine
        self.nodes = self.tester.service_manager.populate_nodes()
        # pop out one NC to fill in
        self.source_nc = self.nodes.pop()

        def set_state(node, state):
            # retrying, see EUCA-6389
            while node.state != state:
                self.tester.debug(node.hostname + ": SET STATE TO " + state)
                enabled_clc.sys("euca-modify-service -s " + state + " " +
                                node.hostname)
                self.tester.sleep(10)
                tmpnodes = self.tester.service_manager.populate_nodes()
                for tmpnode in tmpnodes:
                    if tmpnode.hostname == node.hostname:
                        node = tmpnode

        # stop all the NCs
        for node in self.nodes:
            set_state(node, "STOPPED")

        self.image = self.tester.get_emi(root_device_type="instance-store")
        self.reservation = self.tester.run_instance(
            self.image,
            min=3,
            max=3,
            username=self.args.instance_user,
            keypair=self.keypair.name,
            group=self.group.name,
            zone=self.zone)

        for i in xrange(3):
            instance = self.reservation.instances[i]
            instance_list.append(instance)
            assert isinstance(instance, EuInstance)
            volume_device = None
            if volume_list:
                volume_device = instance.attach_euvolume(volume_list[i])

        self.nodes = self.tester.service_manager.populate_nodes()
        # start all the NCs
        for node in self.nodes:
            if node.hostname is not self.source_nc.hostname:
                set_state(node, "ENABLED")

        self.nodes = self.tester.service_manager.populate_nodes()
        # evacuate source NC
        enabled_clc.sys("source " + self.tester.credpath + "/eucarc && " +
                        self.tester.eucapath +
                        "/usr/sbin/euca-migrate-instances --source " +
                        self.source_nc.machine.hostname)

        def wait_for_evacuation():
            self.tester.service_manager.populate_nodes()
            if self.source_nc.machine.distro.name is "vmware":
                emptyNC = self.source_nc.sys(
                    "esxcli vm process list | grep 'Display Name' | awk '{print $3}'"
                )
            else:
                emptyNC = self.source_nc.get_virsh_list()
            return len(emptyNC) == 0

        self.tester.wait_for_result(wait_for_evacuation,
                                    True,
                                    timeout=600,
                                    poll_wait=60)

        for inst in instance_list:
            self.assertTrue(self.tester.ping(inst.public_dns_name),
                            'Could not ping instance')

        self.tester.terminate_instances(reservation=self.reservation)
        if volume_list:
            self.tester.delete_volumes(volume_list)

    def EvacuateNCWithVol(self):
        volume_list = []
        for i in xrange(self.numberOfResources):
            volume = self.tester.create_volume(zone=self.zone)
            assert isinstance(volume, EuVolume)
            volume_list.append(volume)
        self.EvacuateNC(volume_list)

    def EvacuateNCAllEBS(self):
        self.image = self.tester.get_emi(root_device_type="ebs")
        self.EvacuateNC()
Example #41
0
class CorsTestSuite(EutesterTestCase):
    def __init__(self):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument("--endpoint", default=None)
        self.get_args()
        # Setup basic eutester object
        if self.args.endpoint:
            self.tester = S3ops(credpath=self.args.credpath,
                                endpoint=self.args.endpoint)
        else:
            self.tester = Eucaops(credpath=self.args.credpath,
                                  config_file=self.args.config,
                                  password=self.args.password)

        self.bucket_prefix = "eutester-cors-test-suite-" + str(int(
            time.time()))
        self.buckets_used = set()

    def test_cors_config_mgmt(self):
        '''
        Method: Tests setting, getting, and deleting the CORS config on a bucket
        '''
        test_bucket = self.bucket_prefix + "-simple-test-bucket"
        self.buckets_used.add(test_bucket)
        self.tester.debug(
            "Starting CORS config management tests, using bucket name: " +
            test_bucket)

        try:
            bucket = self.tester.s3.create_bucket(test_bucket)
            if bucket == None:
                self.tester.s3.delete_bucket(test_bucket)
                self.fail(test_bucket + " was not created correctly")
        except (S3ResponseError, S3CreateError) as e:
            self.fail(test_bucket + " create caused exception: " + str(e))

        # Get the CORS config (none yet).
        # Should get 404 Not Found, with "NoSuchCORSConfiguration" in the body.
        try:
            self.tester.debug("Getting (empty) CORS config")
            bucket.get_cors()
            #self.tester.s3.delete_bucket(test_bucket)
            #LPT self.fail("Did not get an S3ResponseError getting CORS config when none exists yet.")
        except S3ResponseError as e:
            if (e.status == 404 and e.reason == "Not Found"
                    and e.code == "NoSuchCORSConfiguration"):
                self.tester.debug(
                    "Caught S3ResponseError with expected contents, " +
                    "getting CORS config when none exists yet.")
            else:
                self.tester.s3.delete_bucket(test_bucket)
                self.fail(
                    "Caught S3ResponseError getting CORS config when none exists yet,"
                    + "but exception contents were unexpected: " + str(e))

        # Set a simple CORS config.
        try:
            self.tester.debug("Setting a CORS config")
            bucket_cors_set = CORSConfiguration()
            bucket_rule_id = "ManuallyAssignedId1"
            bucket_allowed_methods = ['GET', 'PUT']
            bucket_allowed_origins = ['*']
            bucket_allowed_headers = ['*']
            bucket_max_age_seconds = 3000
            #bucket_expose_headers = []
            bucket_cors_set.add_rule(bucket_allowed_methods,
                                     bucket_allowed_origins, bucket_rule_id,
                                     bucket_allowed_headers,
                                     bucket_max_age_seconds)
            bucket.set_cors(bucket_cors_set)
        except S3ResponseError as e:
            self.tester.s3.delete_bucket(test_bucket)
            self.fail("Caught S3ResponseError setting CORS config: " + str(e))

        # Get the CORS config. Should get the config we just set.
        try:
            self.tester.debug("Getting the CORS config we just set")
            bucket_cors_retrieved = bucket.get_cors()
            assert (bucket_cors_retrieved.to_xml() == bucket_cors_set.to_xml(
            )), 'Bucket CORS config: Expected ' + bucket_cors_set.to_xml(
            ) + ', Retrieved ' + bucket_cors_retrieved.to_xml()

        except S3ResponseError as e:
            self.tester.s3.delete_bucket(test_bucket)
            self.fail(
                "Caught S3ResponseError getting CORS config, after setting it successfully: "
                + str(e))

        # Delete the CORS config.
        try:
            self.tester.debug("Deleting the CORS config")
            bucket.delete_cors()
        except S3ResponseError as e:
            self.tester.s3.delete_bucket(test_bucket)
            self.fail(
                "Caught S3ResponseError deleting CORS config, after setting and validating it successfully: "
                + str(e))

        # Get the CORS config (none anymore).
        # Should get 404 Not Found, with "NoSuchCORSConfiguration" in the body.
        try:
            self.tester.debug("Getting (empty again) CORS config")
            bucket.get_cors()
            self.tester.s3.delete_bucket(test_bucket)
            self.fail(
                "Did not get an S3ResponseError getting CORS config after being deleted."
            )
        except S3ResponseError as e:
            self.tester.s3.delete_bucket(test_bucket)
            if (e.status == 404 and e.reason == "Not Found"
                    and e.code == "NoSuchCORSConfiguration"):
                self.tester.debug(
                    "Caught S3ResponseError with expected contents, " +
                    "getting CORS config after being deleted.")
            else:
                self.fail(
                    "Caught S3ResponseError getting CORS config after being deleted,"
                    + "but exception contents were unexpected: " + str(e))

    def test_cors_preflight_requests(self):
        '''
        Method: Tests creating a bucket, 
        setting up a complex CORS config,
        getting it back and validating its contents,  
        sending various preflight OPTIONS requests,
        and validating the preflight responses against the CORS config.
        '''
        self.fail("Feature Not implemented")

    def clean_method(self):
        '''This is the teardown method'''
        #Delete the testing bucket if it is left-over
        self.tester.info('Deleting the buckets used for testing')
        # Can't iterate over a list if we're deleting from it as we iterate, so make a copy
        buckets_used = self.buckets_used.copy()
        for bucket_name in buckets_used:
            try:
                self.tester.info('Checking bucket ' + bucket_name +
                                 ' for possible cleaning/delete')
                self.tester.s3.get_bucket(bucket_name)
                self.tester.info(
                    'Found bucket exists, cleaning and deleting it')
                self.tester.clear_bucket(bucket_name)
                self.buckets_used.remove(bucket_name)
            except BotoServerError as e:
                self.tester.info('Exception checking bucket' + bucket_name +
                                 ': ' + str(e))
        return
Example #42
0
class StickinessBasics(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()

        # Setup basic eutester object
        if self.args.region:
            self.tester = ELBops(credpath=self.args.credpath,
                                 region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath,
                                  config_file=self.args.config,
                                  password=self.args.password)
        self.tester.poll_count = 120

        ### Add and authorize a group for the instance
        self.group = self.tester.add_group(group_name="group-" +
                                           str(int(time.time())))
        self.tester.authorize_group_by_name(group_name=self.group.name)
        self.tester.authorize_group_by_name(group_name=self.group.name,
                                            port=-1,
                                            protocol="icmp")
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" +
                                               str(int(time.time())))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)

        ### Get an image
        self.image = self.args.emi
        if not self.image:
            self.image = self.tester.get_emi()

        ### Populate available zones
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name

        self.load_balancer_port = 80

        (self.web_servers, self.filename) = self.tester.create_web_servers(
            keypair=self.keypair,
            group=self.group,
            zone=self.zone,
            port=self.load_balancer_port,
            filename='instance-name',
            image=self.image)

        self.load_balancer = self.tester.create_load_balancer(
            zones=[self.zone],
            name="test-" + str(int(time.time())),
            load_balancer_port=self.load_balancer_port)
        assert isinstance(self.load_balancer, LoadBalancer)
        self.tester.register_lb_instances(self.load_balancer.name,
                                          self.web_servers.instances)

    def clean_method(self):
        self.tester.cleanup_artifacts()

    def GenerateRequests(self):
        """
        This will test the most basic use case for a load balancer.
        Uses to backend instances with httpd servers.
        """
        dns = self.tester.service_manager.get_enabled_dns()
        lb_ip = dns.resolve(self.load_balancer.dns_name)
        lb_url = "http://{0}:{1}/instance-name".format(lb_ip,
                                                       self.load_balancer_port)
        return self.tester.generate_http_requests(url=lb_url,
                                                  count=100,
                                                  worker_threads=1)

    def session_affinity_test(self):
        lbpolicy = "LB-Policy"
        self.tester.create_lb_cookie_stickiness_policy(
            cookie_expiration_period=300,
            lb_name=self.load_balancer.name,
            policy_name=lbpolicy)
        acpolicy = "AC-Policy"
        self.tester.create_app_cookie_stickiness_policy(
            name="test-cookie",
            lb_name=self.load_balancer.name,
            policy_name=acpolicy)
        """test lb stickiness"""
        self.tester.sleep(2)
        self.tester.set_lb_policy(lb_name=self.load_balancer.name,
                                  lb_port=80,
                                  policy_name=lbpolicy)
        responses = self.GenerateRequests()
        host = responses[0]
        for response in responses:
            if response != host:
                raise Exception(
                    "Expected same response due to load balancer stickiness policy. Got initial response: "
                    + host + " subsequent response: " + response)
        """test app cookie stickiness"""
        self.tester.set_lb_policy(lb_name=self.load_balancer.name,
                                  lb_port=80,
                                  policy_name=acpolicy)
        responses = self.GenerateRequests()
        host = responses[0]
        for response in responses:
            if response != host:
                raise Exception(
                    "Expected same response due to app cookie stickiness policy. Got initial response: "
                    + host + " subsequent response: " + response)
        return
Example #43
0
class InstanceRestore(EutesterTestCase):
    def __init__(self):
        self.setuptestcase()
        self.setup_parser()
        self.get_args()
        # Setup basic eutester object
        self.tester = Eucaops(config_file=self.args.config_file,
                              password=self.args.password)
        self.tester.poll_count = 120

        ### Add and authorize a group for the instance
        self.group = self.tester.add_group(group_name="group-" +
                                           str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name)
        self.tester.authorize_group_by_name(group_name=self.group.name,
                                            port=-1,
                                            protocol="icmp")
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        self.image = self.tester.get_emi(root_device_type="instance-store")
        self.reservation = None
        self.private_addressing = False
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name
        clcs = self.tester.get_component_machines("clc")
        if len(clcs) is 0:
            raise Exception("No CLC found")
        else:
            self.clc = clcs[0]
        self.cur_time = str(int(time.time()))
        self.ncs = self.tester.get_component_machines("nc")

    def clean_method(self):
        ncs = self.tester.get_component_machines("nc")
        for nc in ncs:
            nc.sys("service eucalyptus-nc start")

        ### RESET vmstate properties
        self.tester.modify_property("cloud.vmstate.instance_timeout", "60")
        self.tester.modify_property("cloud.vmstate.terminated_time", "60")
        for nc in self.ncs:
            nc.sys("service eucalyptus-nc start")
        self.tester.cleanup_artifacts()
        try:
            image = self.tester.get_emi(self.image)
        except Exception, e:
            self.tester.register_image(
                image_location=self.image.location,
                ramdisk=self.image.ramdisk_id,
                kernel=self.image.kernel_id,
                virtualization_type=self.image.virtualization_type)
Example #44
0
    pmsg("url:" + str(url) + "\nimg:" + str(img) + "\nuser:"******"\naccount:" + str(account) + "\nzone:" + str(zone) + "\ntype:" +
         str(itype) + "\ngroup:" + str(group_name) + "\nprefix:" +
         str(prefix) + "\nwindows:" + str(windows) + "\nname:" + str(name) +
         "\ndot:" + str(dot) + "\nmd5sum:" + str(md5sum) + "\nconfig:" +
         str(config))

    #Define the bytes per gig
    gig = 1073741824
    #Define timeout based on gig, for transfer disk writing,etc.
    time_per_gig = 300
    #Number of ping attempts used to test instance state, before giving up on a running instance
    ping_retry = 100
    #The eutester cloud tester object
    tester = Eucaops(password=password, config_file=config, credpath=credpath)

    #sets tester to throw exception upon failure
    if (options.eof):
        tester.exit_on_fail = 1
    else:
        tester.exit_on_fail = 0

    try:
        ### Create security group if it does not exist. Add ssh authorization to it.
        try:
            group = tester.add_group(group_name)
            tester.authorize_group_by_name(group.name)
            tester.authorize_group_by_name(group.name,
                                           protocol="icmp",
                                           port=-1)
Example #45
0
class EucaTest(unittest.TestCase):
    def setUp(self):
        self.conf = "cloud.conf"
        self.tester = Eucaops(config_file=self.conf, password="******")
        self.doAuth()
        self.OK = '\033[1m\033[37m\033[42m'
        self.ENDC = '\033[0m'

    def tearDown(self):
        self.tester.cleanup_artifacts()
        self.tester.modify_property('bootstrap.webservices.use_instance_dns',
                                    'false')
        self.tester.delete_keypair(self.keypair)
        self.tester.local("rm " + self.keypair.name + ".pem")
        shutil.rmtree(self.tester.credpath)

    def runInstances(self, numMax):
        self.emi = self.tester.get_emi(root_device_type='ebs')
        #Start instance
        self.reservation = self.tester.run_instance(self.emi,
                                                    keypair=self.keypair.name,
                                                    group=self.group,
                                                    min=1,
                                                    max=numMax,
                                                    is_reachable=False)
        # Make sure the instance is running
        for instance in self.reservation.instances:
            if instance.state == "running":
                self.ip = instance.public_dns_name
                self.instanceid = instance.id

    def runSysCmd(self, cmd):
        self.source = "source " + self.tester.credpath + "/eucarc && "
        self.out = self.tester.sys(self.source + cmd)

    def doAuth(self):
        self.keypair = self.tester.add_keypair()
        self.group = self.tester.add_group()
        self.tester.authorize_group(self.group)

    def test(self):
        self.tester.modify_property('bootstrap.webservices.use_instance_dns',
                                    'true')
        self.runInstances(1)
        self.tester.stop_instances(self.reservation)
        self.runSysCmd('euca-describe-instances ' + self.instanceid)
        # make sure publicdnsname and privatednsname fields are empty in euca-descibe-instances output
        assert str(self.out).count('eucalyptus.internal') == 0
        assert str(self.out).count('eucalyptus.localhost') == 0
        print self.OK + 'SUCCESS: publicdns and privatedns fields are empty in euca-descibe-instances output' + self.ENDC
Example #46
0
class Euca3933(unittest.TestCase):
    def setUp(self):
        self.conf = "cloud.conf"
        self.fakeId = "OOO000000000"
        self.cmdMod = " euca-modify-image-attribute --launch-permission "
        self.tester = Eucaops(config_file=self.conf, password="******")
        self.source = "source " + self.tester.credpath + "/eucarc && "
        self.doAuth()

    def tearDown(self):
        self.tester.cleanup_artifacts()
        self.tester.delete_keypair(self.keypair)
        self.tester.local("rm " + self.keypair.name + ".pem")
        shutil.rmtree(self.tester.credpath)

    def doAuth(self):
        self.keypair = self.tester.add_keypair()
        self.group = self.tester.add_group()
        self.tester.authorize_group(self.group)

    def testValidation(self):
        self.emi = self.tester.get_emi()
        # Try and add --launch-permission with a bad userId
        self.out = self.tester.sys(self.source + self.cmdMod + " -a " +
                                   self.fakeId + " " + self.emi.id)
        # Check output
        self.count = str(self.out).count("Not a valid userId")
        if self.count == 1:
            self.tester.debug(
                "SUCCESS --launch-permission validation error thrown")
            pass
        else:
            self.fail("FAIL no error with bad userID")
        pass
Example #47
0
class CloudWatchCustom(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument('-c', '--command', help='Command to monitor')
        self.parser.add_argument('-n',
                                 '--namespace',
                                 help='Namespace to put data under')
        self.parser.add_argument('-m',
                                 '--metric-name',
                                 help='Metric name to put data under')
        self.parser.add_argument('-u',
                                 '--unit',
                                 default=None,
                                 help="Unit that the value be returned with")
        self.parser.add_argument(
            '-i',
            '--interval',
            default=10,
            type=int,
            help='Time between exectutions of the monitoring task')
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        if self.args.region:
            self.tester = EC2ops(credpath=self.args.credpath,
                                 region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath,
                                  config_file=self.args.config,
                                  password=self.args.password)

    def clean_method(self):
        pass

    def MonitorLocal(self):
        while True:
            try:
                output = self.tester.local(self.args.command)
                self.tester.debug(output)
                value = int(output)
                self.tester.put_metric_data(self.args.namespace,
                                            self.args.metric_name,
                                            value=value,
                                            unit=self.args.unit)
            except subprocess.CalledProcessError:
                self.tester.critical(
                    "Command exited Non-zero not putting data")
            except ValueError:
                self.tester.critical("Command returned non-integer")
            self.tester.sleep(self.args.interval)

    def MonitorRemotes(self):
        while True:
            for machine in self.tester.get_component_machines():
                try:
                    output = "".join(machine.sys(self.args.command, code=0))
                    self.tester.debug(output)
                    value = int(output)
                    ### Push to Hostname dimension
                    self.tester.put_metric_data(
                        self.args.namespace,
                        self.args.metric_name,
                        unit=self.args.unit,
                        dimensions={"Hostname": machine.hostname},
                        value=value)
                    ### Push to aggregate metric as well
                    self.tester.put_metric_data(self.args.namespace,
                                                self.args.metric_name,
                                                unit=self.args.unit,
                                                value=value)
                except CommandExitCodeException:
                    self.tester.critical(
                        "Command exited Non-zero not putting data")
                except ValueError:
                    self.tester.critical("Command returned non-integer")
                except Exception, e:
                    self.tester.critical("Unknown failure: " + str(e))
            self.tester.sleep(self.args.interval)
Example #48
0
    def configure_edge_dual_subnet(self):
        if re.search("edge", self.tester.config["network"], re.IGNORECASE):
            if not hasattr(self.tester, 'service_manager'):
                self.tester = Eucaops(config_file=self.args.config_file, password=self.args.password)
            enabled_clc = self.tester.service_manager.get_enabled_clc()
            ip_addr_add_command = "ip addr add {0}/24 dev {1}"
            ### add private subnet GW interface on CC
            cc = self.tester.get_component_machines("cc00")[0]
            cc_interface = "em1"
            base_ip = self.tester.config["subnet_ip"].strip("0")
            private_subnet = base_ip + "0"
            cc_gw_ip = base_ip + "1"
            cc.sys(ip_addr_add_command.format(cc_gw_ip, cc_interface))

            ### Setup IP forwarding
            cc.sys("sysctl -w net.ipv4.ip_forward=1")

            ### Make sure conflicting dhcpd server is not running on Nodes by deleting
            ### hypervisor's default network
            for node in self.tester.service_manager.get_all_node_controllers():
                node.sys('virsh net-destroy default')

            ### add private interface subnet on NC bridges
            ip_index = 2
            for nc in self.tester.get_component_machines("nc"):
                nc_private_ip = base_ip + str(ip_index)
                ip_index += 1
                nc.sys(ip_addr_add_command.format(nc_private_ip, "br0"))

            ### Chunk out private ip pool
            instance_private_ips = []
            for i in xrange(64):
                instance_private_ips.append(base_ip + str(ip_index + i))
            if hasattr(self.args, "vnet_public_ips"):
                public_ips = self.args.vnet_public_ips
            elif "managed_ips" in self.tester.config:
                public_ips = self.tester.config["managed_ips"]
            else:
                raise Exception("Unable to find public ips. Please provide them with --vnet-public-ips")
            ip_list = public_ips.split()
            if len(ip_list) > 1:
                ### individual ips were passed
                public_ips = ip_list
            else:
                public_ips = [public_ips]

            network_config = {"InstanceDnsDomain": "eucalyptus.internal",
                              "InstanceDnsServers": [enabled_clc.hostname],
                              "PublicIps": public_ips,
                              "Subnets": [],
                              "Clusters": [{"Name": "PARTI00",
                                            "MacPrefix": "d0:0d",
                                            "Subnet": {
                                                "Name": private_subnet,
                                                "Subnet": private_subnet,
                                                "Netmask": "255.255.255.0",
                                                "Gateway": cc_gw_ip
                                            },
                                            "PrivateIps": instance_private_ips
                                            }]
                              }
            self.tester.modify_property("cloud.network.network_configuration", "'" + json.dumps(network_config) + "'")
Example #49
0
class InstanceBasics(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument("--region", default=None)
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        if self.args.region:
            self.tester = EC2ops(credpath=self.args.credpath,
                                 region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath,
                                  config_file=self.args.config,
                                  password=self.args.password)
        self.tester.poll_count = 120

        ### Add and authorize a group for the instance
        self.group = self.tester.add_group(group_name="group-" +
                                           str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name)
        self.tester.authorize_group_by_name(group_name=self.group.name,
                                            port=-1,
                                            protocol="icmp")
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        self.image = self.args.emi
        if not self.image:
            self.image = self.tester.get_emi(root_device_type="instance-store")
        self.address = None
        self.volume = None
        self.snapshot = None
        self.private_addressing = False
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name
        self.reservation = None

    def clean_method(self):
        ### Terminate the reservation if it is still up
        if self.reservation:
            self.assertTrue(self.tester.terminate_instances(self.reservation),
                            "Unable to terminate instance(s)")

        ### DELETE group
        self.tester.delete_group(self.group)

        ### Delete keypair in cloud and from filesystem
        self.tester.delete_keypair(self.keypair)
        os.remove(self.keypath)

    def MyTest(self):
        """
        This case was developed to run through a series of basic instance tests.
             The tests are as follows:
                   - execute run_instances command
                   - make sure that public DNS name and private IP aren't the same
                       (This is for Managed/Managed-NOVLAN networking modes)
                   - test to see if instance is ping-able
                   - test to make sure that instance is accessible via ssh
                       (ssh into instance and run basic ls command)
             If any of these tests fail, the test case will error out, logging the results.
        """
        if not self.reservation:
            self.reservation = self.tester.run_instance(
                self.image, keypair=self.keypair.name, group=self.group.name)
        for instance in self.reservation.instances:
            self.assertTrue(self.tester.wait_for_reservation(self.reservation),
                            'Instance did not go to running')
            self.assertNotEqual(instance.public_dns_name,
                                instance.private_ip_address,
                                'Public and private IP are the same')
            self.assertTrue(self.tester.ping(instance.public_dns_name),
                            'Could not ping instance')
            self.assertFalse(
                instance.found("ls -1 /dev/" + instance.rootfs_device + "2",
                               "No such file or directory"),
                'Did not find ephemeral storage at ' + instance.rootfs_device +
                "2")
Example #50
0
class CloudFormationTemplateURLTests(EutesterTestCase):
    def __init__(self, extra_args=None):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument('--template_urls',
                                 dest='template_urls',
                                 help='comma separated list of template_urls',
                                 default=None)
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        self.show_args()
        self.template_urls = self.args.template_urls.split(',')
        # Setup basic eutester object
        if self.args.region:
            self.tester = CFNops(credpath=self.args.credpath,
                                 region=self.args.region)
        else:
            self.tester = Eucaops(credpath=self.args.credpath,
                                  config_file=self.args.config,
                                  password=self.args.password)
        # Generate a keypair for the instance
        self.keypair = self.tester.add_keypair("keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)

    def Stack_Template_URL_Test(self):
        for url in self.template_urls:
            # get template name from URL, remove file extension and any "-"
            template = os.path.splitext(url.rsplit('/',
                                                   1)[1])[0].replace("-", "")
            self.stack_name = template + str(int(time.time()))
            self.template_parameters = [('KeyName', self.keypair.name),
                                        ('ImageId', self.tester.get_emi().id)]
            self.tester.create_stack(stack_name=self.stack_name,
                                     template_body=None,
                                     template_url=url,
                                     parameters=self.template_parameters)

            def stack_completed():
                stack_status = False
                if len(
                        self.tester.cloudformation.describe_stack_events(
                            self.stack_name)) > 0:
                    stack_info = self.tester.cloudformation.describe_stack_events(
                        self.stack_name)
                    for inf in stack_info:
                        if (inf.logical_resource_id
                                == self.stack_name) and (inf.resource_status
                                                         == "CREATE_COMPLETE"):
                            self.debug("Stack Logical Resource: " +
                                       inf.logical_resource_id)
                            self.debug("Stack Resource Status: " +
                                       inf.resource_status)
                            stack_status = True
                return stack_status

            self.tester.wait_for_result(stack_completed, True, timeout=300)
            self.tester.delete_stack(self.stack_name)

    def clean_method(self):
        self.tester.cleanup_artifacts()
Example #51
0
class WindowsTests(EutesterTestCase):
    
    def __init__(self, 
                 #setup eutester and test environment...
                 tester=None, 
                 config_file=None, 
                 cred_path=None,
                 password=None, 
                 credpath=None, 
                 eof=True,
                 #Information on where to do image bundle work, and related timeouts
                 destpath=None,  
                 time_per_gig = 300,
                 inter_bundle_timeout=120, 
                 upload_timeout=0,
                 work_component=None,
                 component_credpath=None,
                 bucketname = None,
                 #Test env resources...
                 group = None,
                 testvolumes = [],
                 testvolcount = 2,
                 keypair=None, 
                 zone = None,
                 url=None,
                 user_data=None,
                 emi=None,
                 private_addressing=False,
                 instance_password = None,
                 instance_keypath = None,
                 vmtype='m1.xlarge',
                 emi_location=None,
                 image_path=None, #note this must be available on the work_component
                 instance=None,
                 win_proxy_hostname = None, 
                 win_proxy_username = '******',
                 win_proxy_password = None, 
                 win_proxy_keypath = None,
                 authports=['tcp:3389','tcp:80','tcp:443', 'tcp:5985', 'tcp:5986']
                 ):
        if tester is None:
            self.tester = Eucaops( config_file=config_file,password=password,credpath=credpath)
        else:
            self.tester = tester
        self.tester.exit_on_fail = eof
        self.instance = instance
        if self.instance:
            self.instance = self.tester.get_instances(idstring=str(instance))[0]
        self.instance_keypath = instance_keypath
        self.destpath = destpath or '/tmp'
        self.bucketname = bucketname
        self.component = work_component 
        self.component_credpath = component_credpath
        self.time_per_gig = time_per_gig
        self.credpath=credpath or self.tester.credpath
        self.url = url
        self.upload_timeout = upload_timeout
        self.inter_bundle_timeout = inter_bundle_timeout
        self.iu = ImageUtils(tester=self.tester, destpath=self.destpath, time_per_gig=self.time_per_gig, work_component=self.component)
        self.group = group 
        self.keypair = keypair
        self.zonelist = []
        self.emi = self.tester.get_emi(emi)
        self.image_path = image_path
        self.emi_location = emi_location
        if zone is not None:
            self.zonelist.append(zone)
        self.testvolcount = testvolcount
        self.testvolumes = testvolumes
        self.authports=authports
        self.instance_password = instance_password
        self.vmtype= vmtype 
        self.user_data = user_data
        self.private_addressing = private_addressing
        #timeout for run instance command/test
        self.run_timeout=780 
        #setup zone list
        self.setupWindowsZones()
        #setup windows proxy 
        self.win_proxy_hostname = win_proxy_hostname
        self.proxy = None
        if win_proxy_hostname is not None:
            self.setup_proxy(win_proxy_hostname,
                             proxy_keypath = win_proxy_keypath,
                             proxy_username = win_proxy_username,
                             proxy_password = win_proxy_password,
                             debugmethod = lambda msg: self.debug(msg, traceback=2)
                             )
        self.setup_test_env()
        if self.instance and self.proxy:
                self.update_proxy_instance_data()
    
    def setup_proxy(self, proxy_hostname, proxy_keypath=None, proxy_username=None, proxy_password=None, debugmethod=None):
        debugmethod = debugmethod or (lambda msg: self.debug(msg, traceback=3))
        proxy = windowsproxytests.WindowsProxyTests(proxy_hostname, 
                                                         proxy_keypath = proxy_keypath,
                                                         proxy_username = proxy_username,
                                                         proxy_password = proxy_password,
                                                         debugmethod = debugmethod,
                                                         )
        self.proxy = proxy
        self.proxy.win_instance = self.instance
        try:
            self.test_get_windows_instance_password()
        except: pass
        self.proxy.win_password = self.instance_password
        self.proxy.win_keypath = self.instance_keypath
        return proxy

    def setup_test_env(self):
        self.setupWindowsKeypair()
        self.setupWindowsSecurityGroup()
        self.setupWindowsZones()
        
    def get_images_by_location(self, match='windows'):
        retlist=[]
        for image in self.tester.ec2.get_all_images():
            if re.search(match,image.location):
                retlist.append(image)
        return retlist
        
    
        
    def update_proxy_instance_data(self, win_instance=None, instance_password=None ):
        if self.proxy is None:
            return
        self.proxy.win_instance = win_instance or self.instance
        try:
            password = instance_password or self.instance_password
            if password is None:
                password = self.test_get_windows_instance_password()
            self.proxy.win_password = password
        except Exception, e:
            raise Exception('Warning: update_proxy_instance_data: Could not get instance password')    
Example #52
0
class Euca1057(unittest.TestCase):
    def setUp(self):
        self.conf = "cloud.conf"
        self.tester = Eucaops(config_file=self.conf, password="******")
        self.iu = ImageUtils(tester=self.tester, config_file=self.conf)
        self.imgName = "bfebs-centos-vmwaretools-i386.img"
        self.imgUrl = "http://mirror.qa.eucalyptus-systems.com/bfebs-image/vmware/"
        self.errorMsg = "all associated instances must be in the terminated state."
        self.count = 0
        self.doAuth()

    def tearDown(self):
        if self.reservation is not None:
            self.tester.terminate_instances(self.reservation)
        self.out = self.runSysCmd("euca-deregister " + self.emi)
        self.tester.delete_keypair(self.keypair)
        self.tester.local("rm " + self.keypair.name + ".pem")
        shutil.rmtree(self.tester.credpath)

    def runSysCmd(self, cmd):
        self.source = "source " + self.tester.credpath + "/eucarc && "
        self.out = self.tester.sys(self.source + cmd)

    def doAuth(self):
        self.keypair = self.tester.add_keypair()
        self.group = self.tester.add_group()
        self.tester.authorize_group(self.group)

    def testName(self):
        self.emi = self.iu.create_emi_from_url(self.imgUrl + self.imgName)
        self.reservation = self.tester.run_instance(image=self.emi,
                                                    is_reachable=False)

        self.runSysCmd("euca-deregister " + self.emi)
        self.count = +str(self.out).count(self.errorMsg)
        if self.count == 1:
            self.tester.debug("SUCCESS proper error thrown ")
            pass
        else:
            self.fail("FAIL incorrect error thrown ")
Example #53
0
class HAtests(InstanceBasics, BucketTestSuite):
    def __init__(self):
        self.setuptestcase()
        self.setup_parser()
        self.get_args()
        self.tester = Eucaops(config_file=self.args.config_file,
                              password=self.args.password)
        self.servman = self.tester.service_manager
        self.tester.poll_count = 120
        ### Add and authorize a group for the instance
        self.start_time = str(int(time.time()))
        try:
            self.group = self.tester.add_group(group_name="group-" +
                                               self.start_time)
            self.tester.authorize_group_by_name(group_name=self.group.name)
            self.tester.authorize_group_by_name(group_name=self.group.name,
                                                port=-1,
                                                protocol="icmp")
            ### Generate a keypair for the instance
            self.keypair = self.tester.add_keypair("keypair-" +
                                                   self.start_time)
            self.keypath = os.curdir + "/" + self.keypair.name + ".pem"
            self.image = self.tester.get_emi(root_device_type="instance-store")
            self.reservation = None
            self.private_addressing = False
            self.bucket_prefix = "buckettestsuite-" + self.start_time + "-"
            self.test_user_id = self.tester.s3.get_canonical_user_id()
            zones = self.tester.ec2.get_all_zones()
            self.zone = random.choice(zones).name

            self.tester.clc = self.tester.service_manager.get_enabled_clc(
            ).machine
            self.version = self.tester.clc.sys(
                "cat " + self.tester.eucapath +
                "/etc/eucalyptus/eucalyptus-version")[0]
            ### Create standing resources that will be checked after all failures
            ### Instance, volume, buckets
            ###
            self.standing_reservation = self.tester.run_instance(
                keypair=self.keypair.name,
                group=self.group.name,
                zone=self.zone)
            self.volume = self.tester.create_volume(self.zone)
            self.device = self.standing_reservation.instances[0].attach_volume(
                self.volume)
            self.standing_bucket_name = "failover-bucket-" + self.start_time
            self.standing_bucket = self.tester.create_bucket(
                self.standing_bucket_name)
            self.standing_key_name = "failover-key-" + self.start_time
            self.standing_key = self.tester.upload_object(
                self.standing_bucket_name, self.standing_key_name)
            self.standing_key = self.tester.get_objects_by_prefix(
                self.standing_bucket_name, self.standing_key_name)
        except Exception, e:
            self.clean_method()
Example #54
0
#!/usr/bin/python

from eucaops import Eucaops
from eutester import eupopulator
import argparse
import os

parser = argparse.ArgumentParser(
    prog="populate.py",
    description=
    "Populate a user with various resources including snapshots,volumes,buckets,keypairs,security groups",
    usage="%(prog)s --credpath=<path to creds>")
parser.add_argument('--credpath',
                    help="path to user credentials",
                    required=True)
args = parser.parse_args()

tester = Eucaops(credpath=args.credpath)
pop = eupopulator.EuPopulator(tester)

pop.populate()
pop.serialize_resources(args.credpath.strip("/") + "-before.dat")
def main():

    print
    print "===== EUCA-POPULATE-RESOURCES ====="
    print

    ### PARSE ARGUEMENT
    parser = argparse.ArgumentParser(description='Populate User Resources on AWS-Compatible Cloud')
    parser.add_argument('--credpath', default="NONE")
    parser.add_argument("--accountname", default="ui-test-acct-00")
    parser.add_argument("--username", default="user00")
    parser.add_argument("--password", default="mypassword1")
    parser.add_argument("--running-instance-count", type=int, default=0)
    parser.add_argument("--volume-count", type=int, default=0)
    parser.add_argument("--snapshot-count", type=int, default=0)
    parser.add_argument("--keypair-count", type=int, default=1)
    parser.add_argument("--security-group-count", type=int, default=1)
    parser.add_argument("--ip-count", type=int, default=0)
    parser.add_argument("--create-bfebs", type=int, default=0)
    parser.add_argument("--clear-resources", type=int, default=0)
    parser.add_argument("--display-resources", type=int, default=0)
    args = parser.parse_args()
    
    ### PRINT ARGUMENT
    print
    print "=== INPUT ARGUMENT ==="
    print
    if args.credpath is not "NONE":
	print "CREDENTIALS PATH: " + args.credpath
	print
    print "ACCOUNTNAME: " + args.accountname
    print "USERNAME: "******"PASSWORD: "******"RUNNING INSTANCE COUNT: " + str(args.running_instance_count)
    print "VOLUME COUNT: " + str(args.volume_count)
    print "SNAPSHOT COUNT: " + str(args.snapshot_count)
    print "KEYPAIR COUNT: " + str(args.keypair_count)
    print "SECURITY GROUP COUNT: " + str(args.security_group_count)
    print "IP COUNT: " + str(args.ip_count)
    print
    if args.create_bfebs is not 0:
	print "CREATE BFEBS: YES"
	print
    if args.clear_resources is not 0:
	print "CLEAR RESOURCES: YES"
	print
    if args.display_resources is not 0:
	print "DISPLAY RESOURCES: YES"
	print

    print
    print
    print

    ### INITIALIZE EUTESTER OBJECT
    print 
    print "=== INITIALIZE EUTEST OBJECT ==="
    print
#    CANNOT PULL USER CREDENTIALS WITH ONLY ADMIN CREDENTIALS, NEED TO LOG INTO CLC DIRECTLY
#    tester = Eucaops(credpath=args.credpath)
    tester = Eucaops(config_file='2b_tested.lst', password='******')

    ### CREATE NEW ACCOUNT IF NEEDED
    exists_account = create_new_account_if_needed(tester, args.accountname)

    ### CREATE GROUP IF NEEDED
    groupname = "allow-all-group-" + args.accountname
    exists_group = create_new_policy_group_for_account_if_needed(tester, args.accountname, groupname)

    ### CREATE USER IF NEEDED
    exists_user = create_new_user_if_needed(tester, args.accountname, groupname, args.username)

    ### CREATE PASSWORD IF NEEDED
    if exists_user is 0:
	set_password_for_user(tester, args.accountname, args.username, args.password)

    ### DOWNLOAD USER CREDENTIALS
    user_cred_dir = download_user_credentials(tester, args.accountname, args.username)

    print
    print
    print

    ### INITIALIZE EUTESTER OBJECT AS USER
    print
    print "=== INITIALIZE EUTESTER OBJECT AS USER ==="
    print
    user_tester = Eucaops(credpath=user_cred_dir)

    ### DISPLAY RESOURCES AND EXIT
    if args.display_resources is not 0:
    	display_resources(user_tester)
    	exit(0)

    ### CLEAR RESOURCES IF REQUESTED
    if args.clear_resources is not 0:
    	clear_resources(user_tester)
	if args.clear_resources is 2:
    		print
    		print "===== EUCA-POPULATE-RESOURCES: DONE ====="
    		print
		exit(0)

    ### GENERATE KEYPAIR AS USER
    this_keypair = generate_keypairs_for_given_count(user_tester, args.keypair_count)

    ### GENERATE SECURITY GROUPS AS USER
    this_security_group = generate_security_groups_for_given_count(user_tester, args.security_group_count)

    ### ALLOCATE IP AS USER
    allocate_ip_addresses_for_given_count(user_tester, args.ip_count)

    ### GET FIRST AVAILABILITY ZONE
    this_zone = get_name_of_availablity_zone_for_given_index(user_tester, 0)
    
    ### CREATE BFEBS IMAGE
    if args.create_bfebs is not 0:
	create_bfebs_image_as_user(user_tester, this_keypair, this_security_group, this_zone)

    ### CREATE VOLUME AS USER
    this_volume = create_volume_for_given_count(user_tester, this_zone, args.volume_count)

    ### RUN INSTANCE AS USER
    this_reservation = run_instance_for_given_count(user_tester, this_keypair, this_security_group, this_zone, args.running_instance_count)

    ### CREATE SNAPSHOT AS USER
    if args.running_instance_count is not 0:
    	create_snapshot_for_given_count(user_tester, this_reservation.instances[0], this_volume, args.snapshot_count)

    print
    print "===== EUCA-POPULATE-RESOURCES: DONE ====="
    print
    
    exit(0)
Example #56
0
class Euca4229(unittest.TestCase):
    def setUp(self):
        self.conf = "cloud.conf"
        self.cond = 0
        self.tester = Eucaops(config_file=self.conf, password="******")
        self.doAuth()
        self.sbin = self.tester.eucapath + "/usr/sbin/"
        self.source = "source " + self.tester.credpath + "/eucarc && "

    def tearDown(self):
        self.tester.sys(
            self.source + self.sbin +
            "euca-modify-property -p walrus.storagemaxtotalsnapshotsizeingb=50"
        )
        self.tester.cleanup_artifacts()
        self.tester.delete_keypair(self.keypair)
        self.tester.local("rm " + self.keypair.name + ".pem")
        shutil.rmtree(self.tester.credpath)

    def runInstances(self, numMax):
        #Start instance
        self.reservation = self.tester.run_instance(keypair=self.keypair.name,
                                                    group=self.group,
                                                    min=1,
                                                    max=numMax,
                                                    is_reachable=False)
        # Make sure the instance is running
        for instance in self.reservation.instances:
            if instance.state == "running":
                self.ip = instance.public_dns_name
                self.instanceid = instance.id

    def doAuth(self):
        self.keypair = self.tester.add_keypair()
        self.group = self.tester.add_group()
        self.tester.authorize_group(self.group)

    def testEuca4229(self):
        # Get availibility zone
        self.zone = self.tester.get_zones().pop()
        # Get number of already existing snapshots:
        self.num_snaps_before = str(
            self.tester.sys(self.source +
                            "euca-describe-snapshots")).count("SNAPSHOT")
        # Set storagemaxtotalsnapshotsizeingb
        self.tester.sys(
            self.source + self.sbin +
            "euca-modify-property -p walrus.storagemaxtotalsnapshotsizeingb=1")
        # create volume larger than storagemaxtotalsnapshotsizeingb = 1GB
        self.volume = self.tester.create_volume(self.zone, 2, timeout=100)
        # make sure the exception is thrown
        try:
            self.snap = self.tester.create_snapshot(self.volume.id,
                                                    description="snap-4229")
        except Exception as detail:
            self.cond = str(detail).count('maximum allowed object size')
        # Get the current number of snapshots
        self.num_snaps_after = str(
            self.tester.sys(self.source +
                            "euca-describe-snapshots")).count("SNAPSHOT")
        # Check to see if the the error was thrown and make sure no new snapshot-matadata was created
        if self.cond >= 1 and self.num_snaps_after == self.num_snaps_before:
            self.tester.debug("SUCCESS no new snapshot-metadata")
            pass
        else:
            self.fail("FAIL new snapshot-metadata")
Example #57
0
class TaggingBasics(EutesterTestCase):
    def __init__(self, extra_args= None):
        self.setuptestcase()
        self.setup_parser()
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        if self.args.region:
            self.tester = EC2ops( credpath=self.args.credpath, region=self.args.region)
        else:
            self.tester = Eucaops(config_file=self.args.config, password=self.args.password, credpath=self.args.credpath)
        self.tester.poll_count = 120

        ### Add and authorize a group for the instance
        self.group = self.tester.add_group(group_name="group-" + str(time.time()))
        self.tester.authorize_group_by_name(group_name=self.group.name )
        self.tester.authorize_group_by_name(group_name=self.group.name, port=-1, protocol="icmp" )
        ### Generate a keypair for the instance
        self.keypair = self.tester.add_keypair( "keypair-" + str(time.time()))
        self.keypath = '%s/%s.pem' % (os.curdir, self.keypair.name)
        self.image = self.args.emi
        if not self.image:
            self.image = self.tester.get_emi(root_device_type="instance-store")
        self.address = None
        self.volume = None
        self.snapshot = None
        self.private_addressing = False
        zones = self.tester.ec2.get_all_zones()
        self.zone = random.choice(zones).name
        self.reservation = None

    def clean_method(self):
        ### Terminate the reservation if it is still up
        if self.reservation:
            self.assertTrue(self.tester.terminate_instances(self.reservation), "Unable to terminate instance(s)")

        if self.volume:
            self.tester.delete_volume(self.volume,timeout=600)

        if self.snapshot:
            self.tester.delete_snapshot(self.snapshot)

        ### DELETE group
        self.tester.delete_group(self.group)

        ### Delete keypair in cloud and from filesystem
        self.tester.delete_keypair(self.keypair)
        os.remove(self.keypath)

    def InstanceTagging(self):
        """
        This case was developed to exercise tagging of an instance resource
        """
        if not self.reservation:
            self.reservation = self.tester.run_instance(self.image, keypair=self.keypair.name, group=self.group.name)
        test_instance = None
        tags = { u'name': 'instance-tag-test', u'location' : 'over there'}
        for instance in self.reservation.instances:
            instance.create_tags(tags)
            test_instance = instance

        ### Test Filtering , u'tag:location' : 'over there'
        tag_filter = { u'tag:name': u'instance-tag-test'}
        reservations = self.tester.ec2.get_all_instances(filters=tag_filter)
        if len(reservations) != 1:
            raise Exception('Filter for instances returned too many results')
        reservation = reservations[0]
        if self.reservation.id not in reservation.id:
            raise Exception('Wrong instance id returned after filtering, Expected: ' + self.reservation.id  + ' Received: ' + reservation.id )

        ### Test non-tag Filtering
        ### Filters can be found here, most will be tested manually, but a spot check should be added
        ### http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeInstances.html
        new_group = self.tester.add_group("filter-test")
        self.tester.authorize_group_by_name(group_name=new_group.name )
        self.tester.authorize_group_by_name(group_name=new_group.name, port=-1, protocol="icmp" )
        filter_test_reservation = self.tester.run_instance(self.image, keypair=self.keypair.name, group=new_group.name)
        keypair_filter = {u'key-name': self.keypair.name}
        group_filter = {u'group-name': new_group.name}

        keypair_match = self.tester.ec2.get_all_instances(filters=keypair_filter)
        group_match = self.tester.ec2.get_all_instances(filters=group_filter)
        self.tester.terminate_instances(filter_test_reservation)
        self.tester.delete_group(new_group)
        self.tester.delete_keypair(self.keypair)

        if len(group_match) != 1:
            raise Exception("Non-tag Filtering of instances by group name: " + str(len(group_match))  + " expected: 1")
        if len(keypair_match) != 2:
            raise Exception("Non-tag Filtering of instances by keypair name: " + str(len(keypair_match))  + " expected: 2")

        ### Test Deletion
        test_instance.delete_tags(tags)
        instances = self.tester.ec2.get_all_instances(filters=tag_filter)
        if len(instances) != 0:
            raise Exception('Filter returned instances when there shouldnt be any')

        if all(item in test_instance.tags.items() for item in tags.items()):
            raise Exception('Tags still returned after deletion')
        #self.test_restrictions(test_instance)
        #self.test_in_series(test_instance)
        self.tester.terminate_instances(self.reservation)
        self.reservation = None

    def VolumeTagging(self):
        """
        This case was developed to exercise tagging of an instance resource
        """
        self.volume = self.tester.create_volume(zone=self.zone)
        tags = { u'name': 'volume-tag-test', u'location' : 'datacenter'}
        self.volume.create_tags(tags)

        ### Test Filtering
        tag_filter = { u'tag:name': u'volume-tag-test'}
        volumes = self.tester.ec2.get_all_volumes(filters=tag_filter)
        if len(volumes) is 0:
            raise Exception('Filter for instances returned no results ' + str(volumes))
        if len(volumes) is not 1:
            raise Exception('Filter for instances returned too many results ' + str(volumes))
        if volumes[0].id != self.volume.id:
            raise Exception('Wrong volume ID returned after filtering ' + str(volumes) )

        ### Test non-tag Filtering
        ### Filters can be found here, most will be tested manually, but a spot check should be added
        ### http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeImages.html
        vol_size = 3
        filter_test_volume_1 = self.tester.create_volume(zone=self.zone, size=vol_size)
        filter_test_volume_2 = self.tester.create_volume(zone=self.zone, size=vol_size)
        size_filter = {u'size': vol_size }
        id_filter = {u'volume-id': self.volume.id}

        size_match = self.tester.ec2.get_all_volumes(filters=size_filter)
        id_match = self.tester.ec2.get_all_volumes(filters=id_filter)

        self.tester.delete_volume(filter_test_volume_1)
        self.tester.delete_volume(filter_test_volume_2)

        if len(size_match) != 2:
            raise Exception("Non-tag Filtering of volumes by size: " + str(len(size_match))  + " expected: 2")
        if len(id_match) != 1:
            raise Exception("Non-tag Filtering of volumes by id: " + str(len(id_match))  + " expected: 1")

        ### Test Deletion
        self.volume.delete_tags(tags)
        instances = self.tester.ec2.get_all_instances(filters=tag_filter)
        if len(instances) != 0:
            raise Exception('Filter returned volumes when there shouldnt be any')
        if self.volume.tags != {}:
            raise Exception('Tags still returned after deleting them from volume')
        #self.test_restrictions(self.volume)
        #self.test_in_series(self.volume)

    def SnapshotTagging(self):
        """
        This case was developed to exercise tagging of an instance resource
        """
        if not self.volume:
            self.volume = self.tester.create_volume(zone=self.zone)
        self.snapshot = self.tester.create_snapshot_from_volume(self.volume)
        tags = { u'name': 'snapshot-tag-test', u'location' : 'over there'}
        self.snapshot.create_tags(tags)

        ### Test Filtering , u'tag:location' : 'over there'
        tag_filter = { u'tag:name': 'snapshot-tag-test'}
        snapshots = self.tester.ec2.get_all_snapshots(filters=tag_filter)
        if len(snapshots) != 1:
            raise Exception('Filter for instances returned too many results')
        if snapshots[0].id != self.snapshot.id:
            raise Exception('Wrong instance id returned after filtering')

        ### Test non-tag Filtering
        ### Filters can be found here, most will be tested manually, but a spot check should be added
        ### http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeSnapshots.html
        filter_description = "filtering" + str(int(time.time()))
        filter_test_snapshot = self.tester.create_snapshot_from_volume(self.volume, description=filter_description)

        description_filter = {u'description': filter_description }
        volume_filter = {u'volume-id': self.volume.id}

        description_match = self.tester.ec2.get_all_snapshots(filters=description_filter)
        volume_match = self.tester.ec2.get_all_snapshots(filters=volume_filter)

        self.tester.delete_snapshot(filter_test_snapshot)

        if len(description_match) != 1:
            raise Exception("Non-tag Filtering of snapshots by volume description: " + str(len(description_match))  + " expected: 1")

        if len(volume_match) != 2:
            raise Exception("Non-tag Filtering of snapshots by volume id returned: " + str(len(volume_match))  + " expected: 2")

        ### Test Deletion
        self.snapshot.delete_tags(tags)
        instances = self.tester.ec2.get_all_instances(filters=tag_filter)
        if len(instances) != 0:
            raise Exception('Filter returned snapshots when there shouldnt be any')
        if self.snapshot.tags != {}:
            raise Exception('Tags still returned after deleting them from volume')
        #self.test_restrictions(self.snapshot)
        #self.test_in_series(self.snapshot)
        self.tester.delete_snapshot(self.snapshot)
        self.snapshot = None

    def ImageTagging(self):
        """
        This case was developed to exercise tagging of an instance resource
        """
        tags = { u'name': 'image-tag-test', u'location' : 'over there'}
        self.tester.create_tags([self.image.id], tags)

        ### Test Tag Filtering , u'tag:location' : 'over there'
        tag_filter = { u'tag:name': 'image-tag-test'}
        images = self.tester.ec2.get_all_images(filters=tag_filter)
        if len(images) != 1:
            raise Exception('Filter for instances returned too many results')
        if images[0].id != self.image.id:
            raise Exception('Wrong instance id returned after filtering')

        ### Test non-tag Filtering
        ### Filters can be found here, most will be tested manually, but a spot check should be added
        ### http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeImages.html
        image_description = "image-filtering"
        filter_image_id = self.tester.register_image(image_location=self.image.location,description=image_description)

        description_filter = {u'description': image_description }
        location_filter = {u'manifest-location': self.image.location}

        description_match = self.tester.ec2.get_all_images(filters=description_filter)
        location_match = self.tester.ec2.get_all_images(filters=location_filter)
        filter_image = self.tester.get_emi(emi=filter_image_id)
        self.tester.deregister_image(filter_image)

        if len(description_match) != 1:
            raise Exception("Non-tag Filtering of volumes by size: " + str(len(description_match))  + " expected: 1")
        if len(location_match) != 2:
            raise Exception("Non-tag Filtering of volumes by zone: " + str(len(location_match))  + " expected: 2")

        ### Test Deletion
        self.tester.delete_tags([self.image.id], tags)
        images = self.tester.ec2.get_all_images(filters=tag_filter)
        if len(images) != 0:
            raise Exception('Filter returned volumes when there shouldnt be any')
        if self.image.tags != {}:
            raise Exception('Tags still returned after deleting them from image: ' + str(self.image.tags) )
        #self.test_restrictions(self.image)
        #self.test_in_series(self.image)

    def SecurityGroupTagging(self):
        """
        This case was developed to exercise tagging of an security group resource
        """
        tags = { u'name': 'security-tag-test', u'location' : 'over there'}
        self.debug("Security group ID: " + self.group.id)
        self.tester.create_tags([self.group.id], tags)

        ### Test Tag Filtering , u'tag:location' : 'over there'
        tag_filter = { u'tag:name': 'security-tag-test'}
        groups = self.tester.ec2.get_all_security_groups(filters=tag_filter)
        if len(groups) != 1:
            raise Exception('Filter for groups returned too many results')
        if groups[0].id != self.group.id:
            raise Exception('Wrong group id returned after filtering')

        ### Test non-tag Filtering
        ### Filters can be found here, most will be tested manually, but a spot check should be added
        ### http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeSecurityGroups.html
        group_name = "filter-test"
        group_description = "group-filtering"
        filter_group = self.tester.add_group(group_name=group_name, description=group_description)
        filter_group_2 = self.tester.add_group(group_name=group_name + "2", description=group_description)

        description_filter = {u'description': group_description }
        group_id_filter = {u'group-id': filter_group.id}
        description_match = self.tester.ec2.get_all_security_groups(filters=description_filter)
        self.debug("Groups matching description:" + str(description_match))
        group_id_match = self.tester.ec2.get_all_security_groups(filters=group_id_filter)
        self.debug("Groups matching owner-id (" + group_id_filter[u'group-id']  + "):" + str(group_id_match))

        self.tester.delete_group(filter_group)
        self.tester.delete_group(filter_group_2)

        if len(description_match) != 2:
            raise Exception("Non-tag Filtering of security groups by description: " + str(len(description_match))  + " expected: 2")
        if len(group_id_match) != 1:
            raise Exception("Non-tag Filtering of security groups by id: " + str(len(group_id_match))  + " expected: 1")

        ### Test Deletion
        self.tester.delete_tags([self.group.id], tags)
        groups = self.tester.ec2.get_all_security_groups(filters=tag_filter)
        if len(groups) != 0:
            raise Exception('Filter returned volumes when there shouldnt be any')
        if self.image.tags != {}:
            raise Exception('Tags still returned after deleting them from volume')
        #self.test_restrictions(self.group)
        #self.test_in_series(self.group)


    def test_restrictions(self, resource):
        max_tags_number = 10
        max_tags = {}

        for i in xrange(max_tags_number):
            max_tags[u'key' + str(i)] = 'value' + str(i)

        self.test_tag_creation(max_tags, resource=resource, fail_message="Failure when trying to add max allowable tags (" + str(max_tags_number) + ")", expected_outcome=True)
        self.test_tag_deletion(max_tags, resource=resource,fail_message="Failure when trying to delete max allowable tags (" + str(max_tags_number) + ")", expected_outcome=True)

        too_many_tags = {}
        for i in xrange(max_tags_number + 1):
            too_many_tags[u'key' + str(i)] = 'value' + str(i)

        self.test_tag_creation(too_many_tags, resource=resource,fail_message="Allowed too many tags to be created", expected_outcome=False)

        max_key = u'0' * 127

        maximum_key_length = { max_key : 'my value'}
        self.test_tag_creation(maximum_key_length, resource=resource, fail_message="Unable to use a key with " + str(max_key) + " characters", expected_outcome=True)
        self.test_tag_deletion(maximum_key_length, resource=resource, fail_message="Unable to delete a key with " + str(max_key) + " characters", expected_outcome=True)

        key_too_large = { max_key + u'0' : 'my value'}
        self.test_tag_creation(key_too_large, resource=resource, fail_message="Allowed key with more than " + str(max_key) + " chars", expected_outcome=False)

        maximum_value = '0' * 255

        maximum_value_length = { u'my_key': maximum_value}
        self.test_tag_creation(maximum_value_length, resource=resource, fail_message="Unable to use a value with " + str(maximum_value) + " characters", expected_outcome=True)
        self.test_tag_deletion(maximum_value_length, resource=resource, fail_message="Unable to delete a value with " + str(maximum_value) + " characters", expected_outcome=True)

        value_too_large = { u'my_key': maximum_value + '0'}
        self.test_tag_creation(value_too_large, resource=resource, fail_message="Allowed value with more than " + str(maximum_value) + " chars", expected_outcome=False)

        aws_key_prefix = { u'aws:something': 'asdfadsf'}
        self.test_tag_creation(aws_key_prefix, resource=resource, fail_message="Allowed key with 'aws:' prefix'", expected_outcome=False)

        aws_value_prefix = { u'my_key': 'aws:somethingelse'}
        self.test_tag_creation(aws_value_prefix, resource=resource, fail_message="Did not allow creation value with 'aws:' prefix'", expected_outcome=True)
        self.test_tag_creation(aws_value_prefix, resource=resource, fail_message="Did not allow deletion of value with 'aws:' prefix'", expected_outcome=True)

        lower_case = {u'case': 'value'}
        upper_case = {u'CASE': 'value'}
        self.test_tag_creation(lower_case, resource=resource, fail_message="Unable to add key with all lower case", expected_outcome=True)
        self.test_tag_creation(upper_case, resource=resource, fail_message="Case sensitivity not enforced, unable to create tag with different capitalization", expected_outcome=True)
        self.test_tag_deletion(lower_case, resource=resource, fail_message="Unable to delete a tag, when testing case sensitivity", expected_outcome=True)
        self.test_tag_deletion(upper_case, resource=resource, fail_message="Unable to delete a tag, when testing case sensitivity", expected_outcome=True)

    def test_tag_creation(self, tags, resource, fail_message, expected_outcome=True, timeout=600):
        actual_outcome = None
        exception = None
        try:
            resource.create_tags(tags, timeout=timeout)
            actual_outcome =  True
        except Exception, e:
            exception = e
            actual_outcome =  False
        finally:
Example #58
0
 def setUp(self):
     self.conf = "cloud.conf"
     self.tester = Eucaops(config_file=self.conf, password="******")
     self.doAuth()
     self.OK = '\033[1m\033[37m\033[42m'
     self.ENDC = '\033[0m'
Example #59
0
class Euca4268(unittest.TestCase):
    def setUp(self):
        self.conf = "cloud.conf"
        self.tester = Eucaops(config_file=self.conf, password="******")
        self.cond = 1
        self.doAuth()

    def tearDown(self):
        self.tester.cleanup_artifacts()
        self.tester.delete_keypair(self.keypair)
        self.tester.local("rm " + self.keypair.name + ".pem")
        shutil.rmtree(self.tester.credpath)

    def runInstances(self):
        #Start instance
        self.reservation = self.tester.run_instance(keypair=self.keypair.name,
                                                    group=self.group,
                                                    min=2,
                                                    max=2,
                                                    is_reachable=False)
        # Make sure the instance is running
        self.count = 0
        for instance in self.reservation.instances:
            self.count += 1
            if instance.state == "running":
                if self.count == 1:
                    self.ip_one = instance.public_dns_name
                    self.instanceid_one = instance.id
                else:
                    self.ip_two = instance.public_dns_name
                    self.instanceid_two = instance.id

    def runSysCmd(self, cmd):
        self.source = "source " + self.tester.credpath + "/eucarc && "
        self.out = self.tester.sys(self.source + cmd)

    def doAuth(self):
        self.keypair = self.tester.add_keypair()
        self.group = self.tester.add_group()
        self.tester.authorize_group(self.group)
        self.tester.authorize_group(self.group, port=-1, protocol="icmp")

    def testName(self):
        self.runInstances()
        self.tester.ping(self.ip_one, 1)
        self.tester.ping(self.ip_two, 1)
        #make sure instance is reachable
        self.cmd = 'euca-reboot-instances ' + self.instanceid_one + " " + self.instanceid_two
        self.runSysCmd(self.cmd)
        #wait for reboot
        self.tester.sleep(2)
        self.pingable1 = self.tester.ping(self.ip_one, 1)
        self.pingable2 = self.tester.ping(self.ip_two, 1)

        if self.pingable1 == False and self.pingable2 == False:
            self.tester.debug("SUCCESS both instances were rebooted")
            pass
        else:
            self.fail("FAIL both instances not rebooted")
Example #60
0
class Install(EutesterTestCase):

    def __init__(self, download_creds=False, extra_args= None):
        self.setuptestcase()
        self.setup_parser()
        self.parser.add_argument("--euca-url",)
        self.parser.add_argument("--enterprise-url")
        self.parser.add_argument("--branch")
        self.parser.add_argument("--nogpg",action='store_true')
        self.parser.add_argument("--nightly",action='store_true')
        self.parser.add_argument("--lvm-extents")
        self.parser.add_argument("--vnet-mode", default="MANAGED-NOVLAN")
        self.parser.add_argument("--vnet-subnet", default="1.0.0.0")
        self.parser.add_argument("--vnet-netmask", default="255.255.0.0")
        self.parser.add_argument("--vnet-publicips")
        self.parser.add_argument("--vnet-privateips")
        self.parser.add_argument("--vnet_addrspernet", default="32")
        self.parser.add_argument("--vnet_privinterface", default="br0")
        self.parser.add_argument("--vnet_pubinterface", default="br0")
        self.parser.add_argument("--vnet_bridge", default="br0")
        self.parser.add_argument("--vnet-dns", default="8.8.8.8")
        self.parser.add_argument("--root-lv", default="/dev/vg01/")
        self.parser.add_argument("--dnsdomain")
        self.parser.add_argument("--block-device-manager", default="das")
        if extra_args:
            for arg in extra_args:
                self.parser.add_argument(arg)
        self.get_args()
        # Setup basic eutester object
        self.tester = Eucaops( config_file=self.args.config_file, password=self.args.password, download_creds=download_creds)
        #if not self.args.branch and not self.args.euca_url and not self.args.enterprise_url:
        #    self.args.branch = self.args.upgrade_to_branch

    def clean_method(self):
        pass

    def get_repo_url(self, repo = "eucalyptus", branch = "testing"):
        import httplib
        api_host = "packages.release.eucalyptus-systems.com"
        machine = self.tester.get_component_machines("clc")[0]
        path="/api/1/genrepo/?distro="+str(machine.distro.name)+"&releasever=6&arch=x86_64&[email protected]:"+str(repo)+"&ref="+str(branch) + "&allow-old"
        conn=httplib.HTTPConnection(api_host)
        conn.request("GET", path)
        res=conn.getresponse()
        repo_url = res.read().strip()
        self.tester.debug("Setting " + repo + " URL to: " + repo_url)
        return repo_url

    def add_euca_repo(self):
        if self.args.branch:
            self.args.euca_url = self.get_repo_url("eucalyptus", self.args.branch)
        for machine in self.tester.config["machines"]:
            if machine.distro.name is "vmware":
                continue
            machine.add_repo(self.args.euca_url,"euca-upgrade")

    def add_enterprise_repo(self):
        if self.args.branch:
            self.args.enterprise_url =self.get_repo_url("internal", self.args.branch)
        for machine in self.tester.config["machines"]:
            if machine.distro.name is "vmware":
                continue
            machine.add_repo(self.args.enterprise_url, "ent-upgrade")

    def add_repos(self):
        for machine in self.tester.get_component_machines("clc"):
            machine.package_manager.add_repo(self.repo_url, "eucalyptus")
            machine.package_manager.add_repo(self.euca2ools_url, "euca2ools")
        for machine in self.tester.get_component_machines("ws"):
            machine.package_manager.add_repo(self.repo_url, "eucalyptus")
        for machine in self.tester.get_component_machines("cc"):
            machine.package_manager.add_repo(self.repo_url, "eucalyptus")
        for machine in self.tester.get_component_machines("sc"):
            machine.package_manager.add_repo(self.repo_url, "eucalyptus")
        for machine in self.tester.get_component_machines("nc"):
            if machine.distro.name is "vmware":
                continue
            machine.package_manager.add_repo(self.repo_url, "eucalyptus")
            machine.package_manager.add_repo(self.euca2ools_url, "euca2ools")

    def install_packages(self):
        for machine in self.tester.config["machines"]:
            machine.package_manager.install("ntp")
        for machine in self.tester.get_component_machines("clc"):
            machine.package_manager.install("eucalyptus-cloud")
        for machine in self.tester.get_component_machines("ws"):
            machine.package_manager.install("eucalyptus-walrus")
        for machine in self.tester.get_component_machines("cc"):
            machine.package_manager.install("eucalyptus-cc")
        for machine in self.tester.get_component_machines("sc"):
            machine.package_manager.install("eucalyptus-sc")
        for machine in self.tester.get_component_machines("nc"):
            if machine.distro.name is "vmware":
                continue
            machine.package_manager.install("eucalyptus-nc")

    def start_components(self):
        for machine in self.tester.get_component_machines("nc"):
            if machine.distro.name is "vmware":
                continue
            machine.sys("service eucalyptus-nc start", timeout=480)
        for machine in self.tester.get_component_machines("cc"):
            machine.sys("service eucalyptus-cc start", timeout=480)
        for machine in self.tester.get_component_machines("sc"):
            machine.sys("service eucalyptus-cloud start", timeout=480)
        for machine in self.tester.get_component_machines("ws"):
            machine.sys("service eucalyptus-cloud start", timeout=480)
        for machine in self.tester.get_component_machines("clc"):
            machine.sys("service eucalyptus-cloud start", timeout=480)

    def stop_components(self):
        for machine in self.tester.get_component_machines("clc"):
            machine.sys("service eucalyptus-cloud stop", timeout=480)
        for machine in self.tester.get_component_machines("sc"):
            machine.sys("service eucalyptus-cloud stop", timeout=480)
        for machine in self.tester.get_component_machines("ws"):
            machine.sys("service eucalyptus-cloud stop", timeout=480)
        for machine in self.tester.get_component_machines("cc"):
            machine.sys("service eucalyptus-cc stop", timeout=480)
        for machine in self.tester.get_component_machines("nc"):
            if machine.distro.name is "vmware":
                continue
            machine.sys("service eucalyptus-nc stop", timeout=480)

    def initialize_db(self):
        first_clc = self.tester.get_component_machines("clc")[0]
        first_clc.sys("euca_conf --initialize")

    def setup_bridges(self):
        nc_machines = self.tester.get_component_machines("nc")
        bridge_interface = "em1"
        for nc in nc_machines:
            if nc.distro.name is "vmware":
                return
            nc.sys("echo 'DEVICE=br0\nBOOTPROTO=dhcp\nONBOOT=yes\nTYPE=Bridge' > /etc/sysconfig/network-scripts/ifcfg-br0")
            nc.sys("echo 'DEVICE=" + bridge_interface +"\nTYPE=Ethernet\nBRIDGE=br0' > /etc/sysconfig/network-scripts/ifcfg-" + bridge_interface)
            nc.sys("service network restart")

    def extend_logical_volume(self, logical_volume="/dev/vg01/lv_root", extents="50%FREE"):
        if self.args.root_lv:
            logical_volume = self.args.root_lv
        if self.args.lv_extents:
            logical_volume= self.args.lv_extents
        for machine in self.tester.config["machines"]:
            machine.sys("lvextend " + logical_volume + " -l" + extents )
            machine.sys("resize2fs -f " + logical_volume, timeout=12000)

    def wait_for_creds(self, timeout=900):
        def get_creds():
            try:
                self.tester = Eucaops(config_file=self.args.config_file, password=self.args.password,download_creds=False)
                self.tester.get_credentials()
                return True
            except Exception:
                return False
        self.tester.wait_for_result(get_creds, True, timeout=timeout)

    def sync_ssh_keys(self):
        ### Sync CLC SSH key to all machines
        clc = self.tester.get_component_machines("clc")[0]
        clc_pub_key = clc.sys("cat ~/.ssh/id_rsa.pub")[0]
        for machine in self.tester.get_component_machines():
            machine.sys("echo " + clc_pub_key + " >> ~/.ssh/authorized_keys")

        ### Sync CC keys to the proper NCs
        try:
            for cluster in ["00", "01", "02", "03"]:
                for machine in self.tester.get_component_machines("cc" + cluster):
                    cc_pub_key = machine.sys("cat ~/.ssh/id_rsa.pub")[0]
                    for nc in self.tester.get_component_machines("nc" + cluster):
                        nc.sys("echo " + cc_pub_key + " >> ~/.ssh/authorized_keys")
        except IndexError:
            pass

    def remove_host_check(self):
        for machine in self.tester.get_component_machines():
            ssh_config_file = 'Host *\nStrictHostKeyChecking no\nUserKnownHostsFile=/dev/null\n'
            #assert isinstance(machine, Machine)
            ssh_config_file = machine.sftp.open("/root/.ssh/config", "w")
            ssh_config_file.write(ssh_config_file)
            ssh_config_file.close()

    def register_components(self):
        clcs = self.tester.get_component_machines("clc")
        if len(clcs) > 1:
            clcs[0].sys("euca_conf --register-cloud -C eucalyptus -P eucalyptus -H " + clcs[1].hostname)
        walrii = self.tester.get_component_machines("ws")
        for walrus in walrii:
            clcs[0].sys("euca_conf --register-walrus -C walrus -P walrus -H " + walrus.hostname)
        ccs = self.tester.get_component_machines("cc")
        registered_clusters = {1:None, 2:None,3:None,4:None,5:None,6:None,7:None,8:None}
        cluster_number = 1
        for cluster in ccs:
            if not registered_clusters[cluster_number]:
                registered_clusters[cluster_number] = [cluster]
                clcs[0].sys("euca_conf --register-cluster -C cluster" + str(cluster_number) +
                            "A -P cluster" + str(cluster_number) + " -H " + cluster.hostname)
                cluster_number += 1
            else:
                registered_clusters[cluster_number-1].append(cluster)
                clcs[0].sys("euca_conf --register-cluster -C cluster" + str(cluster_number) +
                            "B -P cluster" + str(cluster_number) + " -H " + cluster.hostname)

        cluster_number = 1
        scs = self.tester.get_component_machines("sc")
        registered_scs = {1:None, 2:None,3:None,4:None,5:None,6:None,7:None,8:None}
        for sc in scs:
            if not registered_scs[cluster_number]:
                registered_scs[cluster_number] = [sc]
                clcs[0].sys("euca_conf --register-sc -C storage" + str(cluster_number) +
                            "A -P cluster" + str(cluster_number) + " -H " + sc.hostname)
                cluster_number += 1
            else:
                registered_scs[cluster_number-1].append(sc)
                clcs[0].sys("euca_conf --register-sc -C storage" + str(cluster_number-1) +
                            "B -P cluster" + str(cluster_number-1) + " -H " + sc.hostname)

        try:
            for cluster in ["00", "01", "02","03"]:
                for nc in self.tester.get_component_machines("nc" + cluster):
                    for cc in self.tester.get_component_machines("cc" + cluster):
                        cc.sys("euca_conf --register-nodes " + nc.hostname)
        except IndexError:
            pass

    def set_block_storage_manager(self):
        if not hasattr(self.tester, 'service_manager'):
            self.tester = Eucaops(config_file=self.args.config_file, password=self.args.password)
        enabled_clc = self.tester.service_manager.get_enabled_clc()
        self.zones = self.tester.get_zones()
        for zone in self.zones:
            ebs_manager = "overlay"
            if hasattr(self.args, 'ebs_storage_manager'):
                if re.search("DASManager" ,self.args.ebs_storage_manager):
                    ebs_manager = "das"
                if re.search("SANManager" ,self.args.ebs_storage_manager):
                    if hasattr(self.args, 'san_provider'):
                        if re.search("EquallogicProvider", self.args.san_provider):
                            ebs_manager = "equallogic"
                        if re.search("NetappProvider", self.args.san_provider):
                            ebs_manager = "netapp"
                        if re.search("EmcVnxProvider", self.args.san_provider):
                            ebs_manager = "emc-fastsnap"
            else:
                ebs_manager = self.args.block_device_manager
            self.tester.modify_property(zone + ".storage.blockstoragemanager", ebs_manager)
            self.tester.modify_property(zone + ".storage.dasdevice", self.args.root_lv)

    def set_config_option(self, machine, option, parameter):
        sed_command = 'sed -i -e "s/^.*{0}=.*$/{0}={1}/" {2}/etc/eucalyptus/eucalyptus.conf'.format(option, parameter, self.tester.eucapath)
        machine.sys(sed_command)

    def configure_network(self):
        for machine in self.tester.get_component_machines("cc"):
            self.set_config_option(machine, "VNET_MODE", self.args.vnet_mode)
            self.set_config_option(machine, "VNET_SUBNET", self.args.vnet_subnet)
            self.set_config_option(machine, "VNET_NETMASK", self.args.vnet_netmask)
            self.set_config_option(machine, "VNET_PUBLICIPS", self.args.vnet_publicips)
            self.set_config_option(machine, "VNET_DNS", self.args.vnet_dns)
            self.set_config_option(machine, "VNET_ADDRSPERNET", self.args.vnet_addrspernet)
            self.set_config_option(machine, "VNET_PRIVINTERFACE", self.args.vnet_privinterface)
            self.set_config_option(machine, "VNET_PUBINTERFACE", self.args.vnet_pubinterface)

        for machine in self.tester.get_component_machines("nc"):
            self.set_config_option(machine, "VNET_MODE", self.args.vnet_mode)
            self.set_config_option(machine, "VNET_BRIDGE", self.args.vnet_bridge)

    def configure_edge_dual_subnet(self):
        if re.search("edge", self.tester.config["network"], re.IGNORECASE):
            if not hasattr(self.tester, 'service_manager'):
                self.tester = Eucaops(config_file=self.args.config_file, password=self.args.password)
            enabled_clc = self.tester.service_manager.get_enabled_clc()
            ip_addr_add_command = "ip addr add {0}/24 dev {1}"
            ### add private subnet GW interface on CC
            cc = self.tester.get_component_machines("cc00")[0]
            cc_interface = "em1"
            base_ip = self.tester.config["subnet_ip"].strip("0")
            private_subnet = base_ip + "0"
            cc_gw_ip = base_ip + "1"
            cc.sys(ip_addr_add_command.format(cc_gw_ip, cc_interface))

            ### Setup IP forwarding
            cc.sys("sysctl -w net.ipv4.ip_forward=1")

            ### Make sure conflicting dhcpd server is not running on Nodes by deleting
            ### hypervisor's default network
            for node in self.tester.service_manager.get_all_node_controllers():
                node.sys('virsh net-destroy default')

            ### add private interface subnet on NC bridges
            ip_index = 2
            for nc in self.tester.get_component_machines("nc"):
                nc_private_ip = base_ip + str(ip_index)
                ip_index += 1
                nc.sys(ip_addr_add_command.format(nc_private_ip, "br0"))

            ### Chunk out private ip pool
            instance_private_ips = []
            for i in xrange(64):
                instance_private_ips.append(base_ip + str(ip_index + i))
            if hasattr(self.args, "vnet_public_ips"):
                public_ips = self.args.vnet_public_ips
            elif "managed_ips" in self.tester.config:
                public_ips = self.tester.config["managed_ips"]
            else:
                raise Exception("Unable to find public ips. Please provide them with --vnet-public-ips")
            ip_list = public_ips.split()
            if len(ip_list) > 1:
                ### individual ips were passed
                public_ips = ip_list
            else:
                public_ips = [public_ips]

            network_config = {"InstanceDnsDomain": "eucalyptus.internal",
                              "InstanceDnsServers": [enabled_clc.hostname],
                              "PublicIps": public_ips,
                              "Subnets": [],
                              "Clusters": [{"Name": "PARTI00",
                                            "MacPrefix": "d0:0d",
                                            "Subnet": {
                                                "Name": private_subnet,
                                                "Subnet": private_subnet,
                                                "Netmask": "255.255.255.0",
                                                "Gateway": cc_gw_ip
                                            },
                                            "PrivateIps": instance_private_ips
                                            }]
                              }
            self.tester.modify_property("cloud.network.network_configuration", "'" + json.dumps(network_config) + "'")

    def setup_dns(self):
        if not hasattr(self.tester, 'service_manager'):
            self.tester = Eucaops(config_file=self.args.config_file, password=self.args.password)
        self.tester.modify_property("bootstrap.webservices.use_dns_delegation", "true")
        self.tester.modify_property("bootstrap.webservices.use_instance_dns", "true")
        enabled_dns = self.tester.service_manager.get_enabled_dns()
        if self.args.dnsdomain:
            self.tester.modify_property("system.dns.dnsdomain", self.args.dnsdomain)
        else:
            hostname = self.tester.get_machine_by_ip(enabled_dns.hostname).sys('hostname')[0].split(".")[0]
            domain = hostname + ".autoqa.qa1.eucalyptus-systems.com"
            self.tester.modify_property("system.dns.dnsdomain", domain)
        self.tester.modify_property("system.dns.nameserveraddress", enabled_dns.hostname)

    def clean_method(self):
        pass

    def InstallEuca(self):
        self.initialize_db()
        self.sync_ssh_keys()
        self.remove_host_check()
        self.configure_network()
        self.start_components()
        self.wait_for_creds()
        self.register_components()
        self.set_block_storage_manager()