Пример #1
0
 def test_admin_no_overwrite(self):
     # If there is already a context in the cache creating an admin
     # context will not overwrite it.
     ctx1 = context.RequestContext('111',
                                   '222',
                                   overwrite=True)
     context.get_admin_context()
     self.assertIs(o_context.get_current(), ctx1)
Пример #2
0
 def test_admin_no_overwrite(self):
     # If there is already a context in the cache creating an admin
     # context will not overwrite it.
     ctx1 = context.RequestContext('111',
                                   '222',
                                   overwrite=True)
     context.get_admin_context()
     self.assertIs(o_context.get_current(), ctx1)
Пример #3
0
 def test_failover_segment_delete(self):
     ctxt = context.get_admin_context()
     result = self._create_failover_segment(self._get_fake_values())
     db.failover_segment_delete(ctxt, result['uuid'])
     self.assertRaises(exception.FailoverSegmentNotFound,
                       db.failover_segment_get_by_uuid, self.ctxt,
                       uuidsentinel.fake_uuid)
Пример #4
0
 def test_notification_delete(self):
     ctxt = context.get_admin_context()
     result = self._create_notification(self._get_fake_values())
     db.notification_delete(ctxt, result['notification_uuid'])
     self.assertRaises(exception.NotificationNotFound,
                       db.notification_get_by_uuid, self.ctxt,
                       uuidsentinel.notification)
 def setUp(self):
     super(ProcessFailureTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
     self.process_name = "nova-compute"
     self.service_host = "fake-host"
     self.novaclient = nova.API()
     self.fake_client = fakes.FakeNovaClient()
     # overriding 'wait_period_after_service_update' to 2 seconds
     # to reduce the wait period.
     self.override_config('wait_period_after_service_update', 2)
Пример #6
0
 def setUp(self):
     super(ProcessFailureTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
     self.process_name = "nova-compute"
     self.service_host = "fake-host"
     self.novaclient = nova.API()
     self.fake_client = fakes.FakeNovaClient()
     # overriding 'wait_period_after_service_update' to 2 seconds
     # to reduce the wait period.
     self.override_config('wait_period_after_service_update', 2)
Пример #7
0
 def setUp(self):
     super(HostFailureTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
     # overriding 'wait_period_after_evacuation' and
     # 'wait_period_after_service_update' to 2 seconds to
     # reduce the wait period.
     self.override_config("wait_period_after_evacuation", 2)
     self.override_config("wait_period_after_service_update", 2)
     self.override_config("evacuate_all_instances", False, "host_failure")
     self.instance_host = "fake-host"
     self.novaclient = nova.API()
     self.fake_client = fakes.FakeNovaClient()
Пример #8
0
 def setUp(self):
     super(HostFailureTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
     # overriding 'wait_period_after_evacuation' and
     # 'wait_period_after_service_update' to 2 seconds to
     # reduce the wait period.
     self.override_config("wait_period_after_evacuation", 2)
     self.override_config("wait_period_after_service_update", 2)
     self.override_config("evacuate_all_instances",
                          False, "host_failure")
     self.instance_host = "fake-host"
     self.novaclient = nova.API()
     self.fake_client = fakes.FakeNovaClient()
Пример #9
0
 def setUp(self):
     super(InstanceFailureTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
     self.novaclient = nova.API()
     self.fake_client = fakes.FakeNovaClient()
     self.instance_id = "1"
     # overriding 'wait_period_after_power_off' and
     # 'wait_period_after_power_on' to 2 seconds to
     # reduce the wait period.
     self.override_config('wait_period_after_power_off', 2)
     self.override_config('wait_period_after_power_on', 2)
     self.override_config("process_all_instances",
                          False, "instance_failure")
Пример #10
0
    def purge(self, age_in_days, max_rows):
        """Purge rows older than a given age from masakari tables."""
        try:
            max_rows = utils.validate_integer(max_rows, 'max_rows', -1,
                                              db.MAX_INT)
        except exception.Invalid as exc:
            sys.exit(str(exc))

        try:
            age_in_days = int(age_in_days)
        except ValueError:
            msg = 'Invalid value for age, %(age)s' % {'age': age_in_days}
            sys.exit(str(msg))

        if max_rows == 0:
            sys.exit(_("Must supply value greater than 0 for max_rows."))
        if age_in_days < 0:
            sys.exit(_("Must supply a non-negative value for age."))
        if age_in_days >= (int(time.time()) / 86400):
            sys.exit(_("Maximal age is count of days since epoch."))
        ctx = context.get_admin_context()

        db_api.purge_deleted_rows(ctx, age_in_days, max_rows)
Пример #11
0
 def setUp(self):
     super(DBCommandsTestCase, self).setUp()
     self.commands = manage.DbCommands()
     self.context = context.get_admin_context()
     sys.argv = ['masakari-manage']
Пример #12
0
 def setUp(self):
     super(NovaApiTestCase, self).setUp()
     self.api = nova.API()
     self.ctx = context.get_admin_context()
Пример #13
0
 def setUp(self):
     super(FailoverSegmentsTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
Пример #14
0
 def setUp(self):
     super(NotificationsTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
Пример #15
0
 def setUp(self):
     super(HostsTestCase, self).setUp()
     self.ctxt = context.get_admin_context()
     self.failover_segment = self._get_failover_segment()
Пример #16
0
    def setUp(self):
        super(PurgeDeletedTest, self).setUp()
        self.context = context.get_admin_context()
        self.engine = db_api.get_engine()
        self.conn = self.engine.connect()
        self.notifications = sqlalchemyutils.get_table(self.engine,
                                                       "notifications")
        self.failover_segments = sqlalchemyutils.get_table(
            self.engine, "failover_segments")
        # The hosts table has a FK of segment_id
        self.hosts = sqlalchemyutils.get_table(self.engine, "hosts")

        # Add 6 rows to table
        self.uuidstrs = []
        self.uuid_fs_segments = []
        self.uuid_hosts = []
        for record in range(6):
            notification_uuid = uuid.uuid4().hex
            fs_segment_uuid = uuid.uuid4().hex
            host_uuid = uuid.uuid4().hex
            ins_stmt = self.notifications.insert().values(
                notification_uuid=notification_uuid,
                generated_time=timeutils.utcnow(),
                source_host_uuid=host_uuid,
                type='demo',
                status='failed')
            self.uuidstrs.append(notification_uuid)
            self.conn.execute(ins_stmt)

            ins_stmt = self.failover_segments.insert().values(
                uuid=fs_segment_uuid,
                name='test',
                service_type='demo',
                recovery_method='auto')
            self.uuid_fs_segments.append(fs_segment_uuid)
            self.conn.execute(ins_stmt)

            ins_stmt = self.hosts.insert().values(
                uuid=host_uuid,
                failover_segment_id=fs_segment_uuid,
                name='host1',
                type='demo',
                control_attributes='test')
            self.uuid_hosts.append(host_uuid)
            self.conn.execute(ins_stmt)

        # Set 4 of them deleted, 2 are 60 days ago, 2 are 20 days ago
        self.age_in_days_20 = timeutils.utcnow() - datetime.timedelta(days=20)
        self.age_in_days_60 = timeutils.utcnow() - datetime.timedelta(days=60)

        make_notifications_old = self.notifications.update().where(
            self.notifications.c.notification_uuid.in_(
                self.uuidstrs[1:3])).values(updated_at=self.age_in_days_20)
        make_notifications_older = self.notifications.update().where(
            self.notifications.c.notification_uuid.in_(
                self.uuidstrs[4:6])).values(updated_at=self.age_in_days_60)
        make_failover_segments_old = self.failover_segments.update().where(
            self.failover_segments.c.uuid.in_(
                self.uuid_fs_segments[1:3])).values(
                    deleted_at=self.age_in_days_20)
        make_failover_segments_older = self.failover_segments.update().where(
            self.failover_segments.c.uuid.in_(
                self.uuid_fs_segments[4:6])).values(
                    deleted_at=self.age_in_days_60)
        make_hosts_old = self.hosts.update().where(
            self.hosts.c.uuid.in_(
                self.uuid_hosts[1:3])).values(deleted_at=self.age_in_days_20)
        make_hosts_older = self.hosts.update().where(
            self.hosts.c.uuid.in_(
                self.uuid_hosts[4:6])).values(deleted_at=self.age_in_days_60)

        self.conn.execute(make_notifications_old)
        self.conn.execute(make_notifications_older)
        self.conn.execute(make_failover_segments_old)
        self.conn.execute(make_failover_segments_older)
        self.conn.execute(make_hosts_old)
        self.conn.execute(make_hosts_older)

        dialect = self.engine.url.get_dialect()
        if dialect == sqlite.dialect:
            # We're seeing issues with foreign key support in SQLite 3.6.20
            # SQLAlchemy doesn't support it at all with < SQLite 3.6.19
            # It works fine in SQLite 3.7.
            # Force foreign_key checking if running SQLite >= 3.7
            import sqlite3
            tup = sqlite3.sqlite_version_info
            if tup[0] > 3 or (tup[0] == 3 and tup[1] >= 7):
                self.conn.execute("PRAGMA foreign_keys = ON")
Пример #17
0
    def setUp(self):
        super(PurgeDeletedTest, self).setUp()
        self.context = context.get_admin_context()
        self.engine = db_api.get_engine()
        self.conn = self.engine.connect()
        self.notifications = sqlalchemyutils.get_table(
            self.engine, "notifications")
        self.failover_segments = sqlalchemyutils.get_table(
            self.engine, "failover_segments")
        # The hosts table has a FK of segment_id
        self.hosts = sqlalchemyutils.get_table(
            self.engine, "hosts")

        # Add 6 rows to table
        self.uuidstrs = []
        self.uuid_fs_segments = []
        self.uuid_hosts = []
        for record in range(6):
            notification_uuid = uuid.uuid4().hex
            fs_segment_uuid = uuid.uuid4().hex
            host_uuid = uuid.uuid4().hex
            ins_stmt = self.notifications.insert().values(
                notification_uuid=notification_uuid,
                generated_time=timeutils.utcnow(),
                source_host_uuid=host_uuid,
                type='demo',
                status='failed')
            self.uuidstrs.append(notification_uuid)
            self.conn.execute(ins_stmt)

            ins_stmt = self.failover_segments.insert().values(
                uuid=fs_segment_uuid,
                name='test',
                service_type='demo',
                recovery_method='auto')
            self.uuid_fs_segments.append(fs_segment_uuid)
            self.conn.execute(ins_stmt)

            ins_stmt = self.hosts.insert().values(
                uuid=host_uuid,
                failover_segment_id=fs_segment_uuid,
                name='host1',
                type='demo',
                control_attributes='test')
            self.uuid_hosts.append(host_uuid)
            self.conn.execute(ins_stmt)

        # Set 4 of them deleted, 2 are 60 days ago, 2 are 20 days ago
        self.age_in_days_20 = timeutils.utcnow() - datetime.timedelta(days=20)
        self.age_in_days_60 = timeutils.utcnow() - datetime.timedelta(days=60)

        make_notifications_old = self.notifications.update().where(
            self.notifications.c.notification_uuid.in_(
                self.uuidstrs[1:3])).values(updated_at=self.age_in_days_20)
        make_notifications_older = self.notifications.update().where(
            self.notifications.c.notification_uuid.in_(
                self.uuidstrs[4:6])).values(updated_at=self.age_in_days_60)
        make_failover_segments_old = self.failover_segments.update().where(
            self.failover_segments.c.uuid.in_(
                self.uuid_fs_segments[1:3])).values(
            deleted_at=self.age_in_days_20)
        make_failover_segments_older = self.failover_segments.update().where(
            self.failover_segments.c.uuid.in_(
                self.uuid_fs_segments[4:6])).values(
            deleted_at=self.age_in_days_60)
        make_hosts_old = self.hosts.update().where(
            self.hosts.c.uuid.in_(self.uuid_hosts[1:3])).values(
            deleted_at=self.age_in_days_20)
        make_hosts_older = self.hosts.update().where(
            self.hosts.c.uuid.in_(self.uuid_hosts[4:6])).values(
            deleted_at=self.age_in_days_60)

        self.conn.execute(make_notifications_old)
        self.conn.execute(make_notifications_older)
        self.conn.execute(make_failover_segments_old)
        self.conn.execute(make_failover_segments_older)
        self.conn.execute(make_hosts_old)
        self.conn.execute(make_hosts_older)

        dialect = self.engine.url.get_dialect()
        if dialect == sqlite.dialect:
            # We're seeing issues with foreign key support in SQLite 3.6.20
            # SQLAlchemy doesn't support it at all with < SQLite 3.6.19
            # It works fine in SQLite 3.7.
            # Force foreign_key checking if running SQLite >= 3.7
            import sqlite3
            tup = sqlite3.sqlite_version_info
            if tup[0] > 3 or (tup[0] == 3 and tup[1] >= 7):
                self.conn.execute("PRAGMA foreign_keys = ON")
Пример #18
0
 def periodic_tasks(self, raise_on_error=False):
     """Tasks to be run at a periodic interval."""
     ctxt = context.get_admin_context()
     return self.manager.periodic_tasks(ctxt, raise_on_error=raise_on_error)
Пример #19
0
 def setUp(self):
     super(TaskflowDriverTestCase, self).setUp()
     self.taskflow_driver = driver.TaskFlowDriver()
     self.ctxt = context.get_admin_context()
Пример #20
0
 def setUp(self):
     super(DBCommandsTestCase, self).setUp()
     self.commands = manage.DbCommands()
     self.context = context.get_admin_context()
     sys.argv = ['masakari-manage']
Пример #21
0
 def periodic_tasks(self, raise_on_error=False):
     """Tasks to be run at a periodic interval."""
     ctxt = context.get_admin_context()
     return self.manager.periodic_tasks(ctxt, raise_on_error=raise_on_error)
Пример #22
0
    def setUp(self):
        super(PurgeDeletedTest, self).setUp()
        self.context = context.get_admin_context()
        self.engine = db_api.get_engine()
        self.conn = self.engine.connect()
        self.notifications = sqlalchemyutils.get_table(self.engine,
                                                       "notifications")
        self.failover_segments = sqlalchemyutils.get_table(
            self.engine, "failover_segments")
        # The hosts table has a FK of segment_id
        self.hosts = sqlalchemyutils.get_table(self.engine, "hosts")

        # Add 6 rows to table
        self.uuidstrs = []
        self.uuid_fs_segments = []
        self.uuid_hosts = []
        for record in range(6):
            notification_uuid = uuid.uuid4().hex
            fs_segment_uuid = uuid.uuid4().hex
            host_uuid = uuid.uuid4().hex
            ins_stmt = self.notifications.insert().values(
                notification_uuid=notification_uuid,
                generated_time=timeutils.utcnow(),
                source_host_uuid=host_uuid,
                type='demo',
                status='failed')
            self.uuidstrs.append(notification_uuid)
            self.conn.execute(ins_stmt)

            ins_stmt = self.failover_segments.insert().values(
                uuid=fs_segment_uuid,
                name='test',
                service_type='demo',
                recovery_method='auto')
            self.uuid_fs_segments.append(fs_segment_uuid)
            self.conn.execute(ins_stmt)

            ins_stmt = self.hosts.insert().values(
                uuid=host_uuid,
                failover_segment_id=fs_segment_uuid,
                name='host1',
                type='demo',
                control_attributes='test')
            self.uuid_hosts.append(host_uuid)
            self.conn.execute(ins_stmt)

        # Set 4 of them deleted, 2 are 60 days ago, 2 are 20 days ago
        self.age_in_days_20 = timeutils.utcnow() - datetime.timedelta(days=20)
        self.age_in_days_60 = timeutils.utcnow() - datetime.timedelta(days=60)

        make_notifications_old = self.notifications.update().where(
            self.notifications.c.notification_uuid.in_(
                self.uuidstrs[1:3])).values(updated_at=self.age_in_days_20)
        make_notifications_older = self.notifications.update().where(
            self.notifications.c.notification_uuid.in_(
                self.uuidstrs[4:6])).values(updated_at=self.age_in_days_60)
        make_failover_segments_old = self.failover_segments.update().where(
            self.failover_segments.c.uuid.in_(
                self.uuid_fs_segments[1:3])).values(
                    deleted_at=self.age_in_days_20)
        make_failover_segments_older = self.failover_segments.update().where(
            self.failover_segments.c.uuid.in_(
                self.uuid_fs_segments[4:6])).values(
                    deleted_at=self.age_in_days_60)
        make_hosts_old = self.hosts.update().where(
            self.hosts.c.uuid.in_(
                self.uuid_hosts[1:3])).values(deleted_at=self.age_in_days_20)
        make_hosts_older = self.hosts.update().where(
            self.hosts.c.uuid.in_(
                self.uuid_hosts[4:6])).values(deleted_at=self.age_in_days_60)

        self.conn.execute(make_notifications_old)
        self.conn.execute(make_notifications_older)
        self.conn.execute(make_failover_segments_old)
        self.conn.execute(make_failover_segments_older)
        self.conn.execute(make_hosts_old)
        self.conn.execute(make_hosts_older)

        dialect = self.engine.url.get_dialect()
        if dialect == sqlite.dialect:
            self.conn.execute("PRAGMA foreign_keys = ON")
Пример #23
0
 def setUp(self):
     super(NovaApiTestCase, self).setUp()
     self.api = nova.API()
     self.ctx = context.get_admin_context()
Пример #24
0
 def setUp(self):
     super(TaskflowDriverTestCase, self).setUp()
     self.taskflow_driver = driver.TaskFlowDriver()
     self.ctxt = context.get_admin_context()