Example #1
0
 def test_power_on_powers_on_node(self):
     ip, port, username, password, node_id, context = self.make_context()
     api = RECSAPI(ip, port, username, password)
     mock_post = self.patch(api, "post")
     api.set_power_on_node(node_id)
     self.assertThat(
         mock_post, MockCalledOnceWith("node/%s/manage/power_on" % node_id))
Example #2
0
 def test_get_node_power_state_returns_state(self):
     ip, port, username, password, node_id, context = self.make_context()
     api = RECSAPI(ip, port, username, password)
     expected = dedent("""
         <node health="OK" id="RCU_84055620466592_BB_1_0" state="1" />
     """)
     response = StringIO(expected)
     self.patch(urllib.request, "urlopen", Mock(return_value=response))
     state = api.get_node_power_state("RCU_84055620466592_BB_1_0")
     self.assertEquals(state, "1")
Example #3
0
 def test_extract_from_response_finds_element_content(self):
     ip, port, username, password, node_id, context = self.make_context()
     api = RECSAPI(ip, port, username, password)
     response = dedent("""
         <node health="OK" id="RCU_84055620466592_BB_1_0" state="0" />
     """)
     attribute = "id"
     expected = "RCU_84055620466592_BB_1_0"
     output = api.extract_from_response(response, attribute)
     self.assertThat(output, Equals(expected))
Example #4
0
 def test_get_gets_response(self):
     ip, port, username, password, node_id, context = self.make_context()
     api = RECSAPI(ip, port, username, password)
     command = factory.make_string()
     params = [factory.make_string() for _ in range(3)]
     expected = dedent("""
         <node health="OK" id="RCU_84055620466592_BB_1_0" state="0" />
     """)
     response = StringIO(expected)
     self.patch(urllib.request, "urlopen", Mock(return_value=response))
     output = api.get(command, params)
     self.assertEquals(output, expected)
Example #5
0
 def test_set_boot_source_sets_device(self):
     ip, port, username, password, node_id, context = self.make_context()
     api = RECSAPI(ip, port, username, password)
     boot_source = '2'
     boot_persistent = 'false'
     params = {'source': boot_source, 'persistent': boot_persistent}
     mock_put = self.patch(api, "put")
     api.set_boot_source(node_id, boot_source, boot_persistent)
     self.assertThat(
         mock_put,
         MockCalledOnceWith('node/%s/manage/set_bootsource' % node_id,
                            params=params))
Example #6
0
 def test_set_boot_source_sets_device(self):
     ip, port, username, password, node_id, context = self.make_context()
     api = RECSAPI(ip, port, username, password)
     boot_source = "2"
     boot_persistent = "false"
     params = {"source": boot_source, "persistent": boot_persistent}
     mock_put = self.patch(api, "put")
     api.set_boot_source(node_id, boot_source, boot_persistent)
     self.assertThat(
         mock_put,
         MockCalledOnceWith("node/%s/manage/set_bootsource" % node_id,
                            params=params),
     )
Example #7
0
    def test_get_nodes_gets_nodes(self):
        ip, port, username, password, node_id, context = self.make_context()
        api = RECSAPI(ip, port, username, password)
        response = dedent("""
            <nodeList>
                <node architecture="x86" baseBoardId="RCU_84055620466592_BB_1"
                 health="OK" id="RCU_84055620466592_BB_1_0"
                 ipAddressMgmt="169.254.94.58"
                 macAddressMgmt="02:00:4c:4f:4f:50"
                 subnetMaskMgmt="255.255.0.0"
                />
                <node architecture="x86" baseBoardId="RCU_84055620466592_BB_2"
                 health="OK" id="RCU_84055620466592_BB_2_0"
                 ipAddressCompute="169.254.94.59"
                 macAddressCompute="02:00:4c:4f:4f:51"
                 subnetMaskCompute="255.255.0.0"
                />
                <node architecture="arm" baseBoardId="RCU_84055620466592_BB_3"
                 health="OK" id="RCU_84055620466592_BB_3_2"
                 ipAddressMgmt="169.254.94.60"
                 macAddressMgmt="02:00:4c:4f:4f:52"
                 subnetMaskMgmt="255.255.0.0"
                 ipAddressCompute="169.254.94.61"
                 macAddressCompute="02:00:4c:4f:4f:53"
                 subnetMaskCompute="255.255.0.0"
                />
                <node architecture="x86" baseBoardId="RCU_84055620466592_BB_4"
                 health="OK" id="RCU_84055620466592_BB_4_0"
                />
            </nodeList>
        """)
        mock_get = self.patch(api, "get", Mock(return_value=response))
        expected = {
            "RCU_84055620466592_BB_1_0": {
                "macs": ["02:00:4c:4f:4f:50"],
                "arch": "x86",
            },
            "RCU_84055620466592_BB_2_0": {
                "macs": ["02:00:4c:4f:4f:51"],
                "arch": "x86",
            },
            "RCU_84055620466592_BB_3_2": {
                "macs": ["02:00:4c:4f:4f:52", "02:00:4c:4f:4f:53"],
                "arch": "arm",
            },
        }
        output = api.get_nodes()

        self.expectThat(output, Equals(expected))
        self.expectThat(mock_get, MockCalledOnceWith("node"))
Example #8
0
 def test_put_crashes_on_url_error(self):
     ip, port, username, password, node_id, context = self.make_context()
     api = RECSAPI(ip, port, username, password)
     command = factory.make_string()
     mock_urlopen = self.patch(urllib.request, "urlopen")
     mock_urlopen.side_effect = urllib.error.URLError("URL Error")
     self.assertRaises(PowerConnError, api.put, command, context)