def test_ilo_logout(self, mock_delete, mock_get):
        host = "my-host"
        key = "asimplekey"
        resource_href = "/rest/v1/sessions/something/123"

        response = mock_get.return_value
        response.status_code = 200
        response.json.return_value = {
            "Type": "Collection.0",
            "Items": [{
                "Oem": {
                    "Hp": {
                        "MySession": True
                    }
                },
                "links": {
                    "self": {
                        "href": resource_href
                    }
                }
            }],
        }
        response2 = mock_delete.return_value
        response2.status_code = 200
        ilo_utils.ilo_logout(host, key)
        mock_delete.assert_called_once_with(
            "https://" + host + resource_href,
            headers={"X-Auth-Token": "asimplekey"},
            verify=False
        )
 def _set_onetime_boot(self, server_hardware_uuid, boot_device):
     host_ip, ilo_token = self._get_ilo_access(server_hardware_uuid)
     oneview_ilo_mapping = {
         'HardDisk': 'Hdd',
         'PXE': 'Pxe',
         'CD': 'Cd',
         'USB': 'Usb',
     }
     try:
         ilo_device = oneview_ilo_mapping[boot_device]
         return ilo_utils.set_onetime_boot(host_ip, ilo_token,
                                           ilo_device,
                                           self.allow_insecure_connections)
     except exceptions.IloException as e:
         raise e
     except KeyError as e:
         raise exceptions.IloException(
             "Set one-time boot to %s is not supported." % boot_device
         )
     finally:
         ilo_utils.ilo_logout(host_ip, ilo_token)
 def get_sh_mac_from_ilo(self, server_hardware_uuid, nic_index=0):
     host_ip, ilo_token = self._get_ilo_access(server_hardware_uuid)
     try:
         return ilo_utils.get_mac_from_ilo(host_ip, ilo_token, nic_index)
     finally:
         ilo_utils.ilo_logout(host_ip, ilo_token)