示例#1
0
    def test_dns_record_properties(self):
        test_zone = None
        zone_name = "cb-recprop-{0}.com.".format(helpers.get_uuid())

        with cb_helpers.cleanup_action(lambda: test_zone.delete()):
            test_zone = self.provider.dns.host_zones.create(
                zone_name, "*****@*****.**")
            test_rec = None

            with cb_helpers.cleanup_action(lambda: test_rec.delete()):
                zone_name = "subdomain." + zone_name
                test_rec = test_zone.records.create(
                    zone_name, DnsRecordType.CNAME, data='hello.com.', ttl=500)
                self.assertEqual(test_rec.zone_id, test_zone.id)
                self.assertEqual(test_rec.type, DnsRecordType.CNAME)
                self.assertEqual(test_rec.data, ['hello.com.'])
                self.assertEqual(test_rec.ttl, 500)

            # Check setting data array
            test_rec2 = None
            with cb_helpers.cleanup_action(lambda: test_rec2.delete()):
                MX_DATA = ['10 mx1.hello.com.', '20 mx2.hello.com.']
                test_rec2 = test_zone.records.create(
                    zone_name, DnsRecordType.MX, data=MX_DATA, ttl=300)
                self.assertEqual(test_rec2.zone_id, test_zone.id)
                self.assertEqual(test_rec2.type, DnsRecordType.MX)
                self.assertSetEqual(set(test_rec2.data), set(MX_DATA))
                self.assertEqual(test_rec2.ttl, 300)
示例#2
0
    def test_volume_properties(self):
        label = "cb-volprops-{0}".format(helpers.get_uuid())
        vol_desc = 'newvoldesc1'
        # Declare these variables and late binding will allow
        # the cleanup method access to the most current values
        test_instance = None
        with cb_helpers.cleanup_action(
                lambda: helpers.cleanup_test_resources(test_instance)):
            subnet = helpers.get_or_create_default_subnet(self.provider)
            test_instance = helpers.get_test_instance(self.provider,
                                                      label,
                                                      subnet=subnet)

            test_vol = self.provider.storage.volumes.create(
                label, 1, description=vol_desc)
            with cb_helpers.cleanup_action(lambda: test_vol.delete()):
                test_vol.wait_till_ready()
                self.assertTrue(
                    isinstance(test_vol.size, six.integer_types)
                    and test_vol.size >= 0,
                    "Volume.size must be a positive number, but got %s" %
                    test_vol.size)
                self.assertTrue(
                    test_vol.description is None
                    or isinstance(test_vol.description, six.string_types),
                    "Volume.description must be None or a string. Got: %s" %
                    test_vol.description)
                self.assertIsNone(test_vol.source)
                self.assertIsNone(test_vol.source)
                self.assertIsNotNone(test_vol.create_time)
                self.assertIsNotNone(test_vol.zone_id)
                self.assertIsNone(test_vol.attachments)
                test_vol.attach(test_instance, '/dev/sda2')
                test_vol.wait_for(
                    [VolumeState.IN_USE],
                    terminal_states=[VolumeState.ERROR, VolumeState.DELETED])
                self.assertIsNotNone(test_vol.attachments)
                self.assertIsInstance(test_vol.attachments, AttachmentInfo)
                self.assertEqual(test_vol.attachments.volume, test_vol)
                self.assertEqual(test_vol.attachments.instance_id,
                                 test_instance.id)
                if (self.provider.PROVIDER_ID != 'azure'
                        and self.provider.PROVIDER_ID != 'gcp'
                        and self.provider.PROVIDER_ID != 'openstack'):
                    self.assertEqual(test_vol.attachments.device, "/dev/sda2")
                test_vol.detach()
                test_vol.label = 'newvolname1'
                test_vol.wait_for(
                    [VolumeState.AVAILABLE],
                    terminal_states=[VolumeState.ERROR, VolumeState.DELETED])
                self.assertEqual(test_vol.label, 'newvolname1')
                self.assertEqual(test_vol.description, vol_desc)
                self.assertIsNone(test_vol.attachments)
                test_vol.wait_for(
                    [VolumeState.AVAILABLE],
                    terminal_states=[VolumeState.ERROR, VolumeState.DELETED])
示例#3
0
    def test_create_wildcard_dns_record(self):
        test_zone = None
        zone_name = "cb-dnswild-{0}.com.".format(helpers.get_uuid())

        with cb_helpers.cleanup_action(lambda: test_zone.delete()):
            test_zone = self.provider.dns.host_zones.create(
                zone_name, "*****@*****.**")
            test_rec = None
            with cb_helpers.cleanup_action(lambda: test_rec.delete()):
                test_rec = test_zone.records.create("*.cb-wildcard." +
                                                    zone_name,
                                                    DnsRecordType.A,
                                                    data='10.1.1.1')
    def test_vm_firewall_rule_add_twice(self):
        label = 'cb-fwruletwice-{0}'.format(helpers.get_uuid())

        # Declare these variables and late binding will allow
        # the cleanup method access to the most current values
        fw = None
        with cb_helpers.cleanup_action(
                lambda: helpers.cleanup_test_resources(vm_firewall=fw)):

            subnet = helpers.get_or_create_default_subnet(self.provider)
            net = subnet.network
            fw = self.provider.security.vm_firewalls.create(label=label,
                                                            description=label,
                                                            network=net.id)

            rule = fw.rules.create(direction=TrafficDirection.INBOUND,
                                   protocol='tcp',
                                   from_port=1111,
                                   to_port=1111,
                                   cidr='0.0.0.0/0')
            # attempting to add the same rule twice should succeed
            same_rule = fw.rules.create(direction=TrafficDirection.INBOUND,
                                        protocol='tcp',
                                        from_port=1111,
                                        to_port=1111,
                                        cidr='0.0.0.0/0')
            self.assertEqual(rule, same_rule)
    def test_crud_vm_firewall_rules(self):
        label = 'cb-crudfw-rules-{0}'.format(helpers.get_uuid())

        subnet = helpers.get_or_create_default_subnet(self.provider)
        net = subnet.network

        fw = None
        with cb_helpers.cleanup_action(lambda: fw.delete()):
            fw = self.provider.security.vm_firewalls.create(label=label,
                                                            description=label,
                                                            network=net.id)

            def create_fw_rule(label):
                return fw.rules.create(direction=TrafficDirection.INBOUND,
                                       protocol='tcp',
                                       from_port=1111,
                                       to_port=1111,
                                       cidr='0.0.0.0/0')

            def cleanup_fw_rule(rule):
                if rule:
                    rule.delete()

            sit.check_crud(self,
                           fw.rules,
                           VMFirewallRule,
                           "cb-crudfwrule",
                           create_fw_rule,
                           cleanup_fw_rule,
                           skip_name_check=True)
    def test_object_life_cycle(self):
        # Test object life cycle methods by using a volume.
        label = "cb-objlifecycle-{0}".format(helpers.get_uuid())
        test_vol = None
        with cb_helpers.cleanup_action(lambda: test_vol.delete()):
            test_vol = self.provider.storage.volumes.create(
                label, 1)

            # Waiting for an invalid timeout should raise an exception
            with self.assertRaises(AssertionError):
                test_vol.wait_for([VolumeState.ERROR], timeout=-1, interval=1)
            with self.assertRaises(AssertionError):
                test_vol.wait_for([VolumeState.ERROR], timeout=1, interval=-1)

            # If interval < timeout, an exception should be raised
            with self.assertRaises(AssertionError):
                test_vol.wait_for([VolumeState.ERROR], timeout=10, interval=20)

            test_vol.wait_till_ready()
            # Hitting a terminal state should raise an exception
            with self.assertRaises(WaitStateException):
                test_vol.wait_for([VolumeState.ERROR],
                                  terminal_states=[VolumeState.AVAILABLE])

            # Hitting the timeout should raise an exception
            with self.assertRaises(WaitStateException):
                test_vol.wait_for([VolumeState.ERROR], timeout=0, interval=0)
示例#7
0
 def create_instance_from_image(img):
     img_instance = None
     with cb_helpers.cleanup_action(
             lambda: helpers.cleanup_test_resources(img_instance)):
         img_instance = self.provider.compute.instances.create(
             img_inst_label,
             img,
             helpers.get_provider_test_data(self.provider, 'vm_type'),
             subnet=subnet)
         img_instance.wait_till_ready()
         self.assertIsInstance(img_instance, Instance)
         self.assertEqual(
             img_instance.label, img_inst_label,
             "Instance label {0} is not equal to the expected label"
             " {1}".format(img_instance.label, img_inst_label))
         image_id = img.id
         self.assertEqual(
             img_instance.image_id, image_id,
             "Image id {0} is not equal to the expected id"
             " {1}".format(img_instance.image_id, image_id))
         self.assertIsInstance(img_instance.public_ips, list)
         if img_instance.public_ips:
             self.assertTrue(
                 img_instance.public_ips[0],
                 "public ip should contain a"
                 " valid value if a list of public_ips exist")
         self.assertIsInstance(img_instance.private_ips, list)
         self.assertTrue(img_instance.private_ips[0],
                         "private ip should"
                         " contain a valid value")
示例#8
0
    def test_crud_dns_record(self):
        test_zone = None
        zone_name = "cb-dnsrec-{0}.com.".format(helpers.get_uuid())

        def create_dns_rec(name):
            if name:
                name = name + "." + zone_name
            else:
                name = zone_name
            return test_zone.records.create(name,
                                            DnsRecordType.A,
                                            data='10.1.1.1')

        def cleanup_dns_rec(dns_rec):
            if dns_rec:
                dns_rec.delete()

        with cb_helpers.cleanup_action(lambda: test_zone.delete()):
            test_zone = self.provider.dns.host_zones.create(
                zone_name, "*****@*****.**")
            sit.check_crud(self,
                           test_zone.records,
                           DnsRecord,
                           "cb-dnsrec",
                           create_dns_rec,
                           cleanup_dns_rec,
                           skip_name_check=True)
示例#9
0
 def test_create_dns_zones_not_fully_qualified(self):
     zone_name = "cb-dnszonenfq-{0}.com".format(helpers.get_uuid())
     test_zone = None
     with cb_helpers.cleanup_action(lambda: test_zone.delete()):
         # If zone name is not fully qualified, it should automatically be
         # handled
         test_zone = self.provider.dns.host_zones.create(
             zone_name, "*****@*****.**")
示例#10
0
    def test_snapshot_properties(self):
        label = "cb-snapprop-{0}".format(helpers.get_uuid())
        test_vol = self.provider.storage.volumes.create(label, 1)
        with cb_helpers.cleanup_action(lambda: test_vol.delete()):
            test_vol.wait_till_ready()
            snap_label = "cb-snap-{0}".format(label)
            test_snap = test_vol.create_snapshot(label=snap_label,
                                                 description=snap_label)

            def cleanup_snap(snap):
                if snap:
                    snap.delete()
                    snap.wait_for([SnapshotState.UNKNOWN],
                                  terminal_states=[SnapshotState.ERROR])

            with cb_helpers.cleanup_action(lambda: cleanup_snap(test_snap)):
                test_snap.wait_till_ready()
                self.assertTrue(isinstance(test_vol.size, six.integer_types))
                self.assertEqual(
                    test_snap.size, test_vol.size,
                    "Snapshot.size must match original volume's size: %s"
                    " but is: %s" % (test_vol.size, test_snap.size))
                self.assertTrue(
                    test_vol.description is None
                    or isinstance(test_vol.description, six.string_types),
                    "Snapshot.description must be None or a string. Got: %s" %
                    test_vol.description)
                self.assertEqual(test_vol.id, test_snap.volume_id)
                self.assertIsNotNone(test_vol.create_time)
                test_snap.label = 'snapnewname1'
                test_snap.description = 'snapnewdescription1'
                test_snap.refresh()
                self.assertEqual(test_snap.label, 'snapnewname1')
                self.assertEqual(test_snap.description, 'snapnewdescription1')

                # Test volume creation from a snapshot (via VolumeService)
                sv_label = "cb-snapvol-{0}".format(test_snap.name)
                snap_vol = self.provider.storage.volumes.create(
                    sv_label, 1, snapshot=test_snap)
                with cb_helpers.cleanup_action(lambda: snap_vol.delete()):
                    snap_vol.wait_till_ready()

                # Test volume creation from a snapshot (via Snapshot)
                snap_vol2 = test_snap.create_volume()
                with cb_helpers.cleanup_action(lambda: snap_vol2.delete()):
                    snap_vol2.wait_till_ready()
示例#11
0
    def test_create_dns_rec_not_fully_qualified(self):
        test_zone = None
        root_zone_name = "cb-recprop-{0}.com.".format(helpers.get_uuid())

        with cb_helpers.cleanup_action(lambda: test_zone.delete()):
            test_zone = self.provider.dns.host_zones.create(
                root_zone_name, "*****@*****.**")
            test_rec = None

            with cb_helpers.cleanup_action(lambda: test_rec.delete()):
                zone_name = "subdomain." + root_zone_name
                test_rec = test_zone.records.create(
                    zone_name, DnsRecordType.CNAME, data='hello.com', ttl=500)

            with cb_helpers.cleanup_action(lambda: test_rec.delete()):
                test_rec = test_zone.records.create(
                    root_zone_name, DnsRecordType.MX,
                    data=['10 mx1.hello.com', '20 mx2.hello.com'], ttl=500)
示例#12
0
    def test_cleanup_action_body_has_no_exception(self):
        invoke_order = [""]

        def cleanup_func():
            invoke_order[0] += "cleanup"

        with cb_helpers.cleanup_action(lambda: cleanup_func()):
            invoke_order[0] += "body_"
        self.assertEqual(invoke_order[0], "body_cleanup")
示例#13
0
 def test_clone_provider_zone(self):
     for zone in list(self.provider.compute.regions.current.zones)[:2]:
         cloned_provider = self.provider.clone(zone=zone)
         test_vol = None
         # Currently, volumes are the cheapest object that's actually
         # cross-zonal for all providers
         with cb_helpers.cleanup_action(lambda: test_vol.delete()):
             label = "cb-attachvol-{0}".format(helpers.get_uuid())
             test_vol = cloned_provider.storage.volumes.create(label, 1)
             self.assertEqual(test_vol.zone_id, zone.id)
示例#14
0
    def test_attach_detach_volume(self):
        label = "cb-attachvol-{0}".format(helpers.get_uuid())
        # Declare these variables and late binding will allow
        # the cleanup method access to the most current values
        test_instance = None
        with cb_helpers.cleanup_action(
                lambda: helpers.cleanup_test_resources(test_instance)):
            subnet = helpers.get_or_create_default_subnet(self.provider)
            test_instance = helpers.get_test_instance(self.provider,
                                                      label,
                                                      subnet=subnet)

            test_vol = self.provider.storage.volumes.create(label, 1)
            with cb_helpers.cleanup_action(lambda: test_vol.delete()):
                test_vol.wait_till_ready()
                test_vol.attach(test_instance, '/dev/sda2')
                test_vol.wait_for(
                    [VolumeState.IN_USE],
                    terminal_states=[VolumeState.ERROR, VolumeState.DELETED])
                test_vol.detach()
                test_vol.wait_for(
                    [VolumeState.AVAILABLE],
                    terminal_states=[VolumeState.ERROR, VolumeState.DELETED])