def test_migrate_database_already_initisalised(self, mock_is_db_initialised): mock_is_db_initialised.return_value = True with patch('subprocess.check_call') as check_call: cinder_utils.migrate_database() self.assertFalse(check_call.called) self.assertFalse(self.service_restart.called)
def pgsql_db_changed(): if 'pgsql-db' not in CONFIGS.complete_contexts(): juju_log('pgsql-db relation incomplete. Peer not ready?') return CONFIGS.write(CINDER_CONF) if is_elected_leader(CLUSTER_RES): juju_log('Cluster leader, performing db sync') migrate_database()
def db_changed(): if 'shared-db' not in CONFIGS.complete_contexts(): juju_log('shared-db relation incomplete. Peer not ready?') return CONFIGS.write(CINDER_CONF) if eligible_leader(CLUSTER_RES): juju_log('Cluster leader, performing db sync') migrate_database()
def test_migrate_database(self, mock_uuid, mock_enabled_services): 'It migrates database with cinder-manage' uuid = 'a-great-uuid' mock_uuid.uuid4.return_value = uuid mock_enabled_services.return_value = ['svc1'] rid = 'cluster:0' self.relation_ids.return_value = [rid] args = {'cinder-db-initialised': "unit/0-%s" % uuid} with patch('subprocess.check_call') as check_call: cinder_utils.migrate_database() check_call.assert_called_with(['cinder-manage', 'db', 'sync']) self.relation_set.assert_called_with(relation_id=rid, **args) self.service_restart.assert_called_with('svc1')
def db_changed(): if 'shared-db' not in CONFIGS.complete_contexts(): juju_log('shared-db relation incomplete. Peer not ready?') return CONFIGS.write(CINDER_CONF) if is_elected_leader(CLUSTER_RES): # Bugs 1353135 & 1187508. Dbs can appear to be ready before the units # acl entry has been added. So, if the db supports passing a list of # permitted units then check if we're in the list. allowed_units = relation_get('allowed_units') if allowed_units and local_unit() in allowed_units.split(): juju_log('Cluster leader, performing db sync') migrate_database() else: juju_log('allowed_units either not presented, or local unit ' 'not in acl list: %s' % repr(allowed_units))
def test_migrate_database(self): '''It migrates database with cinder-manage''' with patch('subprocess.check_call') as check_call: cinder_utils.migrate_database() check_call.assert_called_with(['cinder-manage', 'db', 'sync'])