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)
def test_get_stonith_resources_works(self): stub_executor = CliExecutor() stub_executor.get_full_status_xml = MagicMock( side_effect=[XML_PLAIN_RESOURCES]) connector = CliConnector(executor=stub_executor) resources = connector.get_stonith_resources() self.assertEqual(['c-259.stonith', 'c-260.stonith'], [x.id for x in resources])
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))
def test_plain_resources_parsed_also(self): stub_executor = CliExecutor() stub_executor.get_full_status_xml = MagicMock( side_effect=[XML_PLAIN_RESOURCES]) connector = CliConnector(executor=stub_executor) resources = connector.get_resources() self.assertEqual(3, len(resources)) self.assertEqual(['c-259.stonith', 'c-260.stonith', 'MyResource'], [x.id for x in resources])
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)
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])
def __init__(self, connector: PcsConnector = None, credentials: Credentials = None): self.credentials = credentials self.connector: PcsConnector = connector or CliConnector() if credentials: self.connector.set_credentials(credentials) self.connector.ensure_authorized() self._ensure_sane()
def _create_client_and_runner(self) -> Tuple[Client, AppRunner]: 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) stub_client = Client(connector=connector) stub_client = mock_methods(stub_client) runner = AppRunner() runner._get_client = lambda x: stub_client return (stub_client, runner)
def test_status_json_has_correct_figures(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) client = Client(connector=connector) status_text: str = client.get_status(is_full=True) status_obj = json.loads(status_text) rsrc_obj = status_obj['resources']['statistics'] self.assertEqual(71, rsrc_obj['started']) self.assertEqual(0, rsrc_obj['stopped']) self.assertEqual(0, rsrc_obj['starting'])
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)
def test_get_cluster_name_works(self): stub_executor = CliExecutor() stub_executor.get_status_text = MagicMock( side_effect=[GOOD_STATUS_TEXT]) connector = CliConnector(executor=stub_executor) self.assertEqual('mycluster', connector.get_cluster_name())
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()
def test_get_eligible_resource_count_works(self): stub_executor = CliExecutor() stub_executor.get_full_status_xml = MagicMock(return_value=REAL_XML_23) connector = CliConnector(executor=stub_executor) self.assertEqual(71, connector.get_eligible_resource_count())
def test_get_resources_works(self): stub_executor = CliExecutor() stub_executor.get_full_status_xml = MagicMock(side_effect=[GOOD_XML]) connector = CliConnector(executor=stub_executor) resources = connector.get_resources() self.assertEqual(6, len(resources))