Beispiel #1
0
    def test_if_standby_fails_timeout_exception_raised(self):
        stub_executor = CliExecutor()
        stub_executor.get_full_status_xml = MagicMock()
        stub_executor.get_full_status_xml.return_value = GOOD_XML
        stub_executor.shutdown_node = MagicMock()

        connector = CliConnector(executor=stub_executor)

        connector.ensure_shutdown_possible = MagicMock()
        connector.get_nodes = MagicMock(return_value=[
            Node(name='test',
                 online=True,
                 standby=False,
                 unclean=False,
                 resources_running=2)
        ])

        connector.standby_node = MagicMock()

        client = Client(connector=connector)

        with self.assertRaises(TimeoutException):
            client.shutdown_node('test', timeout=2)

        connector.standby_node.assert_called_with('test')
        self.assertFalse(stub_executor.shutdown_node.called)
Beispiel #2
0
    def test_get_nodes_works(self):

        stub_executor = CliExecutor()
        stub_executor.get_full_status_xml = MagicMock()
        stub_executor.get_full_status_xml.return_value = GOOD_XML

        connector = CliConnector(executor=stub_executor)
        nodes = connector.get_nodes()
        self.assertEqual(2, len(nodes))
Beispiel #3
0
    def test_node_online_parsed_correctly(self):
        stub_executor = CliExecutor()
        stub_executor.get_full_status_xml = MagicMock()
        stub_executor.get_full_status_xml.return_value = GOOD_XML

        connector = CliConnector(executor=stub_executor)
        nodes = connector.get_nodes()
        self.assertEqual(2, len(nodes))
        self.assertTrue(nodes[0].online)
        self.assertFalse(nodes[1].online)
Beispiel #4
0
    def test_get_nodes_works(self):
        stub_executor = CliExecutor()
        stub_executor.get_full_status_xml = MagicMock()
        stub_executor.get_full_status_xml.return_value = REAL_XML_23

        connector = CliConnector(executor=stub_executor)
        nodes = connector.get_nodes()
        self.assertEqual(2, len(nodes))
        self.assertEqual(['srvnode-1', 'srvnode-2'], [x.name for x in nodes])
        self.assertEqual([39, 32], [x.resources_running for x in nodes])
Beispiel #5
0
    def test_before_shutdown_standby_invoked(self):
        stub_executor = CliExecutor()
        stub_executor.get_full_status_xml = MagicMock()
        stub_executor.get_full_status_xml.return_value = GOOD_XML

        connector = CliConnector(executor=stub_executor)
        connector.ensure_shutdown_possible = MagicMock()
        connector.manual_shutdown_node = MagicMock()

        connector.get_nodes = MagicMock(
            side_effect=[[
                Node(name='test',
                     online=True,
                     standby=False,
                     unclean=False,
                     resources_running=2)
            ],
                [
                Node(name='test',
                     online=True,
                     standby=False,
                     unclean=False,
                     resources_running=2)
            ],
                [
                Node(name='test',
                     online=True,
                     standby=False,
                     unclean=False,
                     resources_running=0)
            ]])

        connector.standby_node = MagicMock()

        client = Client(connector=connector)

        client.shutdown_node('test')

        connector.standby_node.assert_called_with('test')
        self.assertEqual(1, connector.manual_shutdown_node.call_count)
Beispiel #6
0
 def test_broken_xml_causes_exception(self):
     stub_executor = CliExecutor()
     stub_executor.get_full_status_xml = MagicMock(side_effect=['broken'])
     connector = CliConnector(executor=stub_executor)
     with self.assertRaises(PcsNoStatusException):
         connector.get_nodes()