コード例 #1
0
ファイル: aerostat_test.py プロジェクト: ekoontz/aerostat
    def test_check_master(self):
        """Test check_master funciton."""

        expected_output1 = True
        expected_output2 = False
        fake_service = 'testing'

        fake_instance_id1 = 'test-master-instance'
        fake_instance_id2 = 'test-slave-instance'

        fake_db = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(aerostat, 'get_master')
        aerostat.get_master(
                fake_db, fake_service).AndReturn(
                        'test-master-instance')
        aerostat.get_master(
                fake_db, fake_service).AndReturn(
                        'test-master-instance')

        self.mox.ReplayAll()

        self.assertEqual(expected_output1, aerostat.check_master(
                fake_db, fake_service, fake_instance_id1))
        self.assertEqual(expected_output2, aerostat.check_master(
                fake_db, fake_service, fake_instance_id2))
コード例 #2
0
ファイル: registrar_test.py プロジェクト: ekoontz/aerostat
    def test_change_master(self):
        """Test change_master function."""

        fake_service = "testing"
        fake_service_type = "masterful"
        test_inst1 = "test-instance1"
        test_inst2 = "test-instance2"
        master_inst = test_inst2
        master_hostname = "testing-master"
        slave_hostname = "tesing-slave-1"

        fake_db = self.mox.CreateMockAnything()
        fake_registrar = registrar.Registrar()

        self.mox.StubOutWithMock(aerostat, "check_master")
        aerostat.check_master(fake_db, fake_service, test_inst1).AndReturn(False)
        aerostat.check_master(fake_db, fake_service, test_inst2).AndReturn(True)

        self.mox.StubOutWithMock(aerostat, "get_master")
        aerostat.get_master(fake_db, fake_service).AndReturn(master_inst)

        self.mox.StubOutWithMock(fake_registrar, "change_hostname")
        fake_registrar.change_hostname(fake_db, "", inst=master_inst)
        fake_registrar.change_hostname(fake_db, "", inst=test_inst1)
        fake_registrar.change_hostname(fake_db, master_hostname, inst=test_inst1)
        fake_registrar.change_hostname(fake_db, slave_hostname, inst=master_inst)

        self.mox.StubOutWithMock(fake_registrar, "pick_name")
        # This should only be called when replacing the master.
        fake_registrar.pick_name(fake_db, fake_service, fake_service_type, test_inst2).AndReturn(slave_hostname)

        self.mox.ReplayAll()

        self.assertTrue(fake_registrar.change_master(fake_db, fake_service, fake_service_type, test_inst1))
        self.assertFalse(fake_registrar.change_master(fake_db, fake_service, fake_service_type, test_inst2))