Exemplo n.º 1
0
    def test_get_active_driver_dict_with_old_conductor(self):
        past = datetime.datetime(2000, 1, 1, 0, 0)
        present = past + datetime.timedelta(minutes=2)

        d = 'common-driver'

        h1 = 'old-host'
        d1 = 'old-driver'
        timeutils.set_time_override(override_time=past)
        self._create_test_cdr(id=1, hostname=h1, drivers=[d, d1])

        h2 = 'new-host'
        d2 = 'new-driver'
        timeutils.set_time_override(override_time=present)
        self._create_test_cdr(id=2, hostname=h2, drivers=[d, d2])

        # verify that old-host does not show up in current list
        one_minute = 60
        expected = {d: set([h2]), d2: set([h2])}
        result = self.dbapi.get_active_driver_dict(interval=one_minute)
        self.assertEqual(expected, result)

        # change the interval, and verify that old-host appears
        two_minute = one_minute * 2
        expected = {d: set([h1, h2]), d1: set([h1]), d2: set([h2])}
        result = self.dbapi.get_active_driver_dict(interval=two_minute)
        self.assertEqual(expected, result)
Exemplo n.º 2
0
    def test_get_active_driver_dict_one_host_no_driver(self):
        h = 'fake-host'
        expected = {}

        timeutils.set_time_override()
        self._create_test_cdr(hostname=h, drivers=[])
        result = self.dbapi.get_active_driver_dict(interval=1)
        self.assertEqual(expected, result)
Exemplo n.º 3
0
    def test_get_active_driver_dict_one_host_many_drivers(self):
        h = 'fake-host'
        d1 = 'driver-one'
        d2 = 'driver-two'
        expected = {d1: set([h]), d2: set([h])}

        timeutils.set_time_override()
        self._create_test_cdr(hostname=h, drivers=[d1, d2])
        result = self.dbapi.get_active_driver_dict(interval=1)
        self.assertEqual(expected, result)
Exemplo n.º 4
0
    def test_touch_conductor(self):
        t = datetime.datetime(2000, 1, 1, 0, 0)
        timeutils.set_time_override(override_time=t)
        c = self._create_test_cdr(updated_at=t)
        self.assertEqual(t, timeutils.normalize_time(c['updated_at']))

        t = datetime.datetime(2000, 1, 1, 0, 1)
        timeutils.set_time_override(override_time=t)
        self.dbapi.touch_conductor(c['hostname'])
        c = self.dbapi.get_conductor(c['hostname'])
        self.assertEqual(t, timeutils.normalize_time(c['updated_at']))
Exemplo n.º 5
0
    def test_get_active_driver_dict_many_hosts_one_driver(self):
        h1 = 'host-one'
        h2 = 'host-two'
        d = 'fake-driver'
        expected = {d: set([h1, h2])}

        timeutils.set_time_override()
        self._create_test_cdr(id=1, hostname=h1, drivers=[d])
        self._create_test_cdr(id=2, hostname=h2, drivers=[d])
        result = self.dbapi.get_active_driver_dict(interval=1)
        self.assertEqual(expected, result)
Exemplo n.º 6
0
 def test_create_port(self):
     pdict = post_get_test_port()
     t1 = datetime.datetime(2000, 1, 1, 0, 0)
     timeutils.set_time_override(t1)
     self.post_json('/ports', pdict)
     result = self.get_json('/ports/%s' % pdict['uuid'])
     self.assertEqual(pdict['uuid'], result['uuid'])
     self.assertFalse(result['updated_at'])
     return_created_at = timeutils.parse_isotime(
                         result['created_at']).replace(tzinfo=None)
     self.assertEqual(t1, return_created_at)
Exemplo n.º 7
0
    def test_get_active_driver_dict_many_hosts_and_drivers(self):
        h1 = 'host-one'
        h2 = 'host-two'
        h3 = 'host-three'
        d1 = 'driver-one'
        d2 = 'driver-two'
        expected = {d1: set([h1, h2]), d2: set([h2, h3])}

        timeutils.set_time_override()
        self._create_test_cdr(id=1, hostname=h1, drivers=[d1])
        self._create_test_cdr(id=2, hostname=h2, drivers=[d1, d2])
        self._create_test_cdr(id=3, hostname=h3, drivers=[d2])
        result = self.dbapi.get_active_driver_dict(interval=1)
        self.assertEqual(expected, result)
Exemplo n.º 8
0
 def test_update_byid(self):
     extra = {'foo': 'bar'}
     t1 = datetime.datetime(2000, 1, 1, 0, 0)
     timeutils.set_time_override(t1)
     response = self.patch_json('/ports/%s' % self.pdict['uuid'],
                                [{'path': '/extra/foo',
                                  'value': 'bar',
                                  'op': 'add'}])
     self.assertEqual(response.content_type, 'application/json')
     self.assertEqual(response.status_code, 200)
     result = self.get_json('/ports/%s' % self.pdict['uuid'])
     self.assertEqual(result['extra'], extra)
     return_updated_at = timeutils.parse_isotime(
                         result['updated_at']).replace(tzinfo=None)
     self.assertEqual(t1, return_updated_at)
Exemplo n.º 9
0
    def test_list_active_conductor_drivers(self):
        # create some conductors with different timestamps
        now = datetime.datetime(2000, 1, 1, 0, 0)
        then = now + datetime.timedelta(hours=1)

        d1 = [u'not-this-one']
        timeutils.set_time_override(override_time=now)
        self._create_test_cdr(id=1, hostname='d1', drivers=d1)

        d2 = [u'foo', u'bar']
        d3 = [u'another']
        timeutils.set_time_override(override_time=then)
        self._create_test_cdr(id=2, hostname='d2', drivers=d2)
        self._create_test_cdr(id=3, hostname='d3', drivers=d3)

        # verify that res contains d2 and d3, but not the old d1
        res = self.dbapi.list_active_conductor_drivers(interval=60)
        drivers = d2 + d3
        self.assertEqual(sorted(res), sorted(drivers))

        # change the interval, and verify that d1 appears
        res = self.dbapi.list_active_conductor_drivers(interval=7200)
        drivers = d1 + d2 + d3
        self.assertEqual(sorted(res), sorted(drivers))
Exemplo n.º 10
0
 def setUp(self):
     super(TimeOverride, self).setUp()
     timeutils.set_time_override()
     self.addCleanup(timeutils.clear_time_override)
Exemplo n.º 11
0
 def setUp(self):
     super(TimeOverride, self).setUp()
     timeutils.set_time_override()
     self.addCleanup(timeutils.clear_time_override)
Exemplo n.º 12
0
 def setUp(self):
     super(DbConductorTestCase, self).setUp()
     self.dbapi = dbapi.get_instance()
     timeutils.set_time_override()
     self.addCleanup(timeutils.clear_time_override)