def test_fanout(self): group = self.useFixture( utils.RpcServerGroupFixture(self.conf, self.url)) client = group.client('all', cast=True) client.append(text='open') client.append(text='stack') client.add(increment=2) client.add(increment=10) client.sync() group.sync(server='all') for s in group.servers: self.assertIn(s.endpoint.sval, ["openstack", "stackopen"]) self.assertEqual(12, s.endpoint.ival)
def test_server_in_group(self): group = self.useFixture( utils.RpcServerGroupFixture(self.conf, self.url)) client = group.client() data = [c for c in 'abcdefghijklmn'] for i in data: client.append(text=i) for s in group.servers: self.assertThat(len(s.endpoint.sval), matchers.GreaterThan(0)) actual = [[c for c in s.endpoint.sval] for s in group.servers] self.assertThat(actual, utils.IsValidDistributionOf(data))
def test_specific_server(self): group = self.useFixture(utils.RpcServerGroupFixture(self.url)) client = group.client(1) client.append(text='open') self.assertEqual('openstack', client.append(text='stack')) client.add(increment=2) self.assertEqual(12, client.add(increment=10)) self.assertEqual(9, client.subtract(increment=3)) self.assertEqual('openstack', group.servers[1].endpoint.sval) self.assertEqual(9, group.servers[1].endpoint.ival) for i in [0, 2]: self.assertEqual('', group.servers[i].endpoint.sval) self.assertEqual(0, group.servers[i].endpoint.ival)
def test_server_in_group(self): group = self.useFixture(utils.RpcServerGroupFixture(self.url)) client = group.client(cast=True) for i in range(20): client.add(increment=1) group.sync() total = 0 for s in group.servers: ival = s.endpoint.ival self.assertThat(ival, matchers.GreaterThan(0)) self.assertThat(ival, matchers.LessThan(20)) total += ival self.assertEqual(20, total)
def test_specific_server(self): group = self.useFixture(utils.RpcServerGroupFixture(self.url)) client = group.client(1, cast=True) client.append(text='open') client.append(text='stack') client.add(increment=2) client.add(increment=10) group.sync() self.assertEqual('openstack', group.servers[1].endpoint.sval) self.assertEqual(12, group.servers[1].endpoint.ival) for i in [0, 2]: self.assertEqual('', group.servers[i].endpoint.sval) self.assertEqual(0, group.servers[i].endpoint.ival)
def test_specific_server(self): group = self.useFixture( utils.RpcServerGroupFixture(self.conf, self.rpc_url)) client = group.client(1, cast=True) client.append(text='open') client.append(text='stack') client.add(increment=2) client.add(increment=10) time.sleep(0.3) client.sync() group.sync(1) self.assertIn(group.servers[1].endpoint.sval, ["openstack", "stackopen"]) self.assertEqual(12, group.servers[1].endpoint.ival) for i in [0, 2]: self.assertEqual('', group.servers[i].endpoint.sval) self.assertEqual(0, group.servers[i].endpoint.ival)
def test_server_in_group(self): if self.url.startswith("amqp:"): self.skipTest("QPID-6307") group = self.useFixture(utils.RpcServerGroupFixture(self.url)) client = group.client(cast=True) for i in range(20): client.add(increment=1) for i in range(len(group.servers)): # expect each server to get a sync client.sync() group.sync(server="all") total = 0 for s in group.servers: ival = s.endpoint.ival self.assertThat(ival, matchers.GreaterThan(0)) self.assertThat(ival, matchers.LessThan(20)) total += ival self.assertEqual(20, total)
def test_functional(self): # verify call metrics is sent and reflected in oslo.metrics self.config(metrics_socket_file='/var/tmp/metrics_collector.sock', group='oslo_messaging_metrics') metric_server = subprocess.Popen(["python3", "-m", "oslo_metrics"]) time.sleep(1) group = self.useFixture( utils.RpcServerGroupFixture(self.conf, self.rpc_url)) client = group.client(1) client.add(increment=1) time.sleep(1) r = requests.get('http://localhost:3000') for line in r.text.split('\n'): if 'client_invocation_start_total{' in line: self.assertEqual('1.0', line[-3:]) elif 'client_invocation_end_total{' in line: self.assertEqual('1.0', line[-3:]) elif 'client_processing_seconds_count{' in line: self.assertEqual('1.0', line[-3:]) metric_server.terminate()
def test_exception(self): group = self.useFixture( utils.RpcServerGroupFixture(self.conf, self.url)) client = group.client(1) client.add(increment=2) self.assertRaises(ValueError, client.subtract, increment=3)
def _test_failover_scenario(self, enable_cancel_on_failover=False): # NOTE(sileht): run this test only if functional suite run of a driver # that use rabbitmq as backend self.driver = os.environ.get('TRANSPORT_DRIVER') if self.driver not in self.DRIVERS: self.skipTest("TRANSPORT_DRIVER is not set to a rabbit driver") # NOTE(sileht): Allow only one response at a time, to # have only one tcp connection for reply and ensure it will failover # correctly self.config(heartbeat_timeout_threshold=1, rpc_conn_pool_size=1, kombu_reconnect_delay=0, rabbit_retry_interval=0, rabbit_retry_backoff=0, enable_cancel_on_failover=enable_cancel_on_failover, group='oslo_messaging_rabbit') self.pifpaf = self.useFixture( rabbitmq.RabbitMQDriver(cluster=True, port=5692)) self.url = self.pifpaf.env["PIFPAF_URL"] self.n1 = self.pifpaf.env["PIFPAF_RABBITMQ_NODENAME1"] self.n2 = self.pifpaf.env["PIFPAF_RABBITMQ_NODENAME2"] self.n3 = self.pifpaf.env["PIFPAF_RABBITMQ_NODENAME3"] # ensure connections will be establish to the first node self.pifpaf.stop_node(self.n2) self.pifpaf.stop_node(self.n3) self.servers = self.useFixture( utils.RpcServerGroupFixture(self.conf, self.url, endpoint=self, names=["server"])) # Don't randomize rabbit hosts self.useFixture( fixtures.MockPatch('oslo_messaging._drivers.impl_rabbit.random', side_effect=lambda x: x)) # NOTE(sileht): this connects server connections and reply # connection to nodename n1 self.client = self.servers.client(0) self.client.ping() self._check_ports(self.pifpaf.port) # Switch to node n2 self.pifpaf.start_node(self.n2) self.assertEqual("callback done", self.client.kill_and_process()) self.assertEqual("callback done", self.client.just_process()) self._check_ports(self.pifpaf.get_port(self.n2)) # Switch to node n3 self.pifpaf.start_node(self.n3) time.sleep(0.1) self.pifpaf.kill_node(self.n2, signal=signal.SIGKILL) time.sleep(0.1) self.assertEqual("callback done", self.client.just_process()) self._check_ports(self.pifpaf.get_port(self.n3)) self.pifpaf.start_node(self.n1) time.sleep(0.1) self.pifpaf.kill_node(self.n3, signal=signal.SIGKILL) time.sleep(0.1) self.assertEqual("callback done", self.client.just_process()) self._check_ports(self.pifpaf.get_port(self.n1))
def test_exception(self): group = self.useFixture(utils.RpcServerGroupFixture(self.url)) client = group.client(1) client.add(increment=2) f = lambda: client.subtract(increment=3) self.assertThat(f, matchers.raises(ValueError))