def create_test_rsdns_entry(self):
     """Create an entry using the RsDnsInstanceEntryFactory."""
     instance = {'uuid': '000136c0-effa-4711-a747-a5b9fbfcb3bd', 'id': '10'}
     ip = "10.100.2.7"
     factory = RsDnsInstanceEntryFactory(dns_domain_id=DNS_DOMAIN_ID)
     entry = factory.create_entry(instance)
     entry.content = ip
     self.driver.create_entry(entry)
     entries = self.driver.get_entries_by_name(name=entry.name)
     assert_equal(1, len(entries))
     assert_equal(ip, entries[0].content)
     assert_equal(FLAGS.dns_ttl, entries[0].ttl)
 def create_test_rsdns_entry(self):
     """Create an entry using the RsDnsInstanceEntryFactory."""
     instance = {'uuid': '000136c0-effa-4711-a747-a5b9fbfcb3bd', 'id': '10'}
     ip = "10.100.2.7"
     factory = RsDnsInstanceEntryFactory(dns_domain_id=DNS_DOMAIN_ID)
     entry = factory.create_entry(instance)
     entry.content = ip
     self.driver.create_entry(entry)
     entries = self.driver.get_entries_by_name(name=entry.name)
     assert_equal(1, len(entries))
     assert_equal(ip, entries[0].content)
     assert_equal(FLAGS.dns_ttl, entries[0].ttl)
class RsdnsEventletTests(object):
    """Makes sure the RSDNS client can be used from multiple green threads."""

    def assert_record_created(self, index):
        msg = "Record %d wasn't created!" % index
        assert_true(index in self.new_records, msg)

    @before_class(enabled=WHITE_BOX and should_run_rsdns_tests())
    def create_driver(self):
        """Creates the DNS Driver used in subsequent tests."""
        self.driver = utils.import_object(FLAGS.dns_driver)
        self.entry_factory = RsDnsInstanceEntryFactory()
        self.test_uuid = uuid.uuid4().hex
        self.new_records = {}

    def make_record(self, index):
        """Creates a record with the form 'eventlet-%s-%d'."""
        uuid = "eventlet-%s-%d" % (self.test_uuid, index)
        instance = {'uuid': uuid}
        entry = self.entry_factory.create_entry(instance)
        entry.name = uuid + "." + self.entry_factory.default_dns_zone.name
        entry.content = "123.123.123.123"
        self.driver.create_entry(entry)
        self.new_records[index] = True

    @test(enabled=WHITE_BOX and should_run_rsdns_tests())
    def use_dns_from_a_single_thread(self):
        """Add DNS records one at a time."""
        self.new_records = {}
        for index in range(-1, -5, -1):
            self.make_record(index)
            self.assert_record_created(index)

    @test(enabled=WHITE_BOX and should_run_rsdns_tests())
    def use_dns_from_multiple_greenthreads(self):
        """Add multiple DNS records at once."""
        self.new_records = {}

        def make_record(index):
            def __cb():
                self.make_record(index)
                self.assert_record_created(index)
                return index
            return __cb

        pile = eventlet.GreenPile()
        indices = range(1, 4)
        for index in indices:
            pile.spawn(make_record(index))

        list(pile)  # Wait for them to finish
        for index in indices:
            self.assert_record_created(index)
Beispiel #4
0
class RsdnsEventletTests(object):
    """Makes sure the RSDNS client can be used from multiple green threads."""
    def assert_record_created(self, index):
        msg = "Record %d wasn't created!" % index
        assert_true(index in self.new_records, msg)

    @before_class(enabled=WHITE_BOX and should_run_rsdns_tests())
    def create_driver(self):
        """Creates the DNS Driver used in subsequent tests."""
        self.driver = utils.import_object(FLAGS.dns_driver)
        self.entry_factory = RsDnsInstanceEntryFactory()
        self.test_uuid = uuid.uuid4().hex
        self.new_records = {}

    def make_record(self, index):
        """Creates a record with the form 'eventlet-%s-%d'."""
        uuid = "eventlet-%s-%d" % (self.test_uuid, index)
        instance = {'uuid': uuid}
        entry = self.entry_factory.create_entry(instance)
        entry.name = uuid + "." + self.entry_factory.default_dns_zone.name
        entry.content = "123.123.123.123"
        self.driver.create_entry(entry)
        self.new_records[index] = True

    @test(enabled=WHITE_BOX and should_run_rsdns_tests())
    def use_dns_from_a_single_thread(self):
        """Add DNS records one at a time."""
        self.new_records = {}
        for index in range(-1, -5, -1):
            self.make_record(index)
            self.assert_record_created(index)

    @test(enabled=WHITE_BOX and should_run_rsdns_tests())
    def use_dns_from_multiple_greenthreads(self):
        """Add multiple DNS records at once."""
        self.new_records = {}

        def make_record(index):
            def __cb():
                self.make_record(index)
                self.assert_record_created(index)
                return index

            return __cb

        pile = eventlet.GreenPile()
        indices = range(1, 4)
        for index in indices:
            pile.spawn(make_record(index))

        list(pile)  # Wait for them to finish
        for index in indices:
            self.assert_record_created(index)
class WhenCreatingAnEntryForAnInstance(unittest.TestCase):
    # This isn't a unit test because RsDnsInstanceEntryFactory connects to the
    # service.

    def setUp(self):
        self.creator = RsDnsInstanceEntryFactory()

    def test_should_concatanate_strings(self):
        instance = {'id': '56', 'uuid': '000136c0-effa-4711-a747-a5b9fbfcb3bd'}
        entry = self.creator.create_entry(instance)
        expected_name = "%s.%s" % (hashlib.sha1(
            instance['uuid']).hexdigest(), FLAGS.dns_domain_name)
        self.assertEqual(expected_name,
                         entry.name,
                         msg="Entry name should match - %s" % entry.name)
        self.assertEqual(None, entry.content)
        self.assertEqual("A", entry.type)
        self.assertEqual(FLAGS.dns_ttl, entry.ttl)
        self.assertEqual(None, entry.priority)
        self.assertEqual(FLAGS.dns_domain_name, entry.dns_zone.name)
        if not entry.dns_zone.id:
            self.fail(msg="DNS Zone Id should not be empty")
class WhenCreatingAnEntryForAnInstance(unittest.TestCase):
    # This isn't a unit test because RsDnsInstanceEntryFactory connects to the
    # service.

    def setUp(self):
        self.creator = RsDnsInstanceEntryFactory()

    def test_should_concatanate_strings(self):
        instance = {'id': '56',
                    'uuid': '000136c0-effa-4711-a747-a5b9fbfcb3bd'}
        entry = self.creator.create_entry(instance)
        expected_name = "%s.%s" % (hashlib.sha1(instance['uuid']).hexdigest(),
                                   FLAGS.dns_domain_name)
        self.assertEqual(expected_name, entry.name,
                         msg="Entry name should match - %s" % entry.name)
        self.assertEqual(None, entry.content)
        self.assertEqual("A", entry.type)
        self.assertEqual(FLAGS.dns_ttl, entry.ttl)
        self.assertEqual(None, entry.priority)
        self.assertEqual(FLAGS.dns_domain_name, entry.dns_zone.name)
        if not entry.dns_zone.id:
            self.fail(msg="DNS Zone Id should not be empty")
 def setUp(self):
     self.creator = RsDnsInstanceEntryFactory()
 def create_driver(self):
     """Creates the DNS Driver used in subsequent tests."""
     self.driver = utils.import_object(FLAGS.dns_driver)
     self.entry_factory = RsDnsInstanceEntryFactory()
     self.test_uuid = uuid.uuid4().hex
     self.new_records = {}
 def setUp(self):
     self.creator = RsDnsInstanceEntryFactory()
Beispiel #10
0
 def create_driver(self):
     """Creates the DNS Driver used in subsequent tests."""
     self.driver = utils.import_object(FLAGS.dns_driver)
     self.entry_factory = RsDnsInstanceEntryFactory()
     self.test_uuid = uuid.uuid4().hex
     self.new_records = {}