Beispiel #1
0
 def test_get_url_with_ip(self):
     driver = OpenBMCPowerDriver()
     context = make_context()
     ip = context.get('power_address').encode('utf-8')
     expected_url = b"https://%s" % ip
     url = driver.get_uri(context)
     self.assertEqual(expected_url, url)
Beispiel #2
0
    def test__power_on(self):
        driver = OpenBMCPowerDriver()
        system_id = factory.make_name('system_id')
        context = make_context()
        url = driver.get_uri(context,
                             HOST_STATE + 'RequestedHostTransition')
        mock_file_body_producer = self.patch(
            openbmc_module, 'FileBodyProducer')
        dataon = FileBodyProducer(BytesIO(json.dumps(
            HOST_ON).encode('utf-8')))
        mock_openbmc_request = self.patch(driver, 'openbmc_request')
        mock_openbmc_request.return_value = dataon
        mock_file_body_producer.return_value = dataon
        mock_power_query = self.patch(driver, 'power_query')
        mock_power_query.return_value = 'on'
        mock_command = self.patch(driver, 'command')
        mock_command.return_value = SAMPLE_JSON_HOSTOFF
        mock_set_pxe_boot = self.patch(driver, 'set_pxe_boot')

        yield driver.power_on(system_id, context)
        self.assertThat(mock_power_query, MockCalledOnceWith(
            system_id, context))
        self.assertThat(mock_set_pxe_boot, MockCalledWith(
            context))
        self.assertThat(mock_command, MockCalledWith(
            context, b'PUT', url, dataon))
Beispiel #3
0
 def test_get_url_with_http(self):
     driver = OpenBMCPowerDriver()
     context = make_context()
     context["power_address"] = join("http://", context["power_address"])
     expected_url = context.get("power_address").encode("utf-8")
     url = driver.get_uri(context)
     self.assertEqual(expected_url, url)
Beispiel #4
0
 def test_get_url_with_https(self):
     driver = OpenBMCPowerDriver()
     context = make_context()
     context['power_address'] = join(
         "https://", context['power_address'])
     expected_url = context.get('power_address').encode('utf-8')
     url = driver.get_uri(context)
     self.assertEqual(expected_url, url)
Beispiel #5
0
 def test_power_query_queries_on(self):
     driver = OpenBMCPowerDriver()
     power_change = "on"
     system_id = factory.make_name('system_id')
     context = make_context()
     mock_power_query = self.patch(driver, 'power_query')
     mock_power_query.return_value = 'on'
     power_state = yield driver.power_query(system_id, context)
     self.assertEquals(power_state, power_change)
Beispiel #6
0
    def test__power_off(self):
        driver = OpenBMCPowerDriver()
        system_id = factory.make_name("system_id")
        context = make_context()
        url = driver.get_uri(context, HOST_STATE + "RequestedHostTransition")
        mock_file_body_producer = self.patch(openbmc_module,
                                             "FileBodyProducer")
        dataoff = FileBodyProducer(
            BytesIO(json.dumps(HOST_OFF).encode("utf-8")))
        mock_openbmc_request = self.patch(driver, "openbmc_request")
        mock_openbmc_request.return_value = dataoff
        mock_file_body_producer.return_value = dataoff
        mock_command = self.patch(driver, "command")
        mock_command.return_value = SAMPLE_JSON_HOSTOFF
        mock_set_pxe_boot = self.patch(driver, "set_pxe_boot")

        yield driver.power_off(system_id, context)
        self.assertThat(mock_set_pxe_boot, MockCalledOnceWith(context))
        self.assertThat(mock_command,
                        MockCalledOnceWith(context, b"PUT", url, dataoff))
Beispiel #7
0
 def test_missing_packages(self):
     driver = OpenBMCPowerDriver()
     missing = driver.detect_missing_packages()
     self.assertItemsEqual([], missing)
Beispiel #8
0

# Register all the power drivers.
power_drivers = [
    AMTPowerDriver(),
    APCPowerDriver(),
    DLIPowerDriver(),
    HMCPowerDriver(),
    IPMIPowerDriver(),
    LXDPowerDriver(),
    ManualPowerDriver(),
    MoonshotIPMIPowerDriver(),
    MSCMPowerDriver(),
    MicrosoftOCSPowerDriver(),
    NovaPowerDriver(),
    OpenBMCPowerDriver(),
    RECSPowerDriver(),
    RedfishPowerDriver(),
    SeaMicroPowerDriver(),
    UCSMPowerDriver(),
    VirshPowerDriver(),
    VMwarePowerDriver(),
    WedgePowerDriver(),
]
for driver in power_drivers:
    PowerDriverRegistry.register_item(driver.name, driver)


# Pod drivers are also power drivers.
for driver_name, driver in PodDriverRegistry:
    PowerDriverRegistry.register_item(driver_name, driver)