def test_rabbitmq_cluster(self): a = self.useFixture(rabbitmq.RabbitMQDriver(cluster=True, port=12345)) self.assertEqual( "rabbit://%(user)s:%(pass)s@localhost:%(port1)d," "%(user)s:%(pass)s@localhost:%(port2)d," "%(user)s:%(pass)s@localhost:%(port3)d//" % { "user": a.username, "pass": a.password, "port1": a.port, "port2": a.port + 1, "port3": a.port + 2 }, os.getenv("PIFPAF_URL")) self.assertEqual(a.nodename + "-1@localhost", os.getenv("PIFPAF_RABBITMQ_NODENAME")) self.assertEqual(a.nodename + "-1@localhost", os.getenv("PIFPAF_RABBITMQ_NODENAME1")) self.assertEqual(a.nodename + "-2@localhost", os.getenv("PIFPAF_RABBITMQ_NODENAME2")) self.assertEqual(a.nodename + "-3@localhost", os.getenv("PIFPAF_RABBITMQ_NODENAME3")) self.assertEqual(str(a.port), os.getenv("PIFPAF_RABBITMQ_PORT")) a.kill_node(a.nodename + "-2@localhost") a.stop_node(a.nodename + "-3@localhost") a.start_node(a.nodename + "-3@localhost") a.start_node(a.nodename + "-2@localhost")
def test_rabbitmq(self): a = self.useFixture(rabbitmq.RabbitMQDriver()) self.assertEqual( "rabbit://%s:%s@localhost:%d//" % (a.username, a.password, a.port), os.getenv("PIFPAF_URL")) self.assertEqual(a.nodename + "@localhost", os.getenv("PIFPAF_RABBITMQ_NODENAME")) self.assertEqual(str(a.port), os.getenv("PIFPAF_RABBITMQ_PORT"))
def test_rabbitmq_cluster(self): a = self.useFixture(rabbitmq.RabbitMQDriver(cluster=True, port=12345)) self.assertEqual( "rabbit://%s:%s@localhost:%d,localhost:%d,localhost:%d//" % (a.username, a.password, a.port, a.port + 1, a.port + 2), os.getenv("PIFPAF_URL")) self.assertEqual(a.nodename + "-1@localhost", os.getenv("PIFPAF_RABBITMQ_NODENAME")) self.assertEqual(a.nodename + "-1@localhost", os.getenv("PIFPAF_RABBITMQ_NODENAME1")) self.assertEqual(a.nodename + "-2@localhost", os.getenv("PIFPAF_RABBITMQ_NODENAME2")) self.assertEqual(a.nodename + "-3@localhost", os.getenv("PIFPAF_RABBITMQ_NODENAME3")) self.assertEqual(str(a.port), os.getenv("PIFPAF_RABBITMQ_PORT")) a.kill_node(a.nodename + "-2@localhost") a.stop_node(a.nodename + "-3@localhost") a.start_node(a.nodename + "-3@localhost")
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))