Merge pull request #33 from rackerlabs/hardware_specific_os_install_device
RFR: Hardware-Specific OS Install Device
This commit is contained in:
commit
c3f1130e38
@ -118,7 +118,7 @@ class TeethAgent(object):
|
||||
self.api = api.TeethAgentAPIServer(self)
|
||||
self.command_results = collections.OrderedDict()
|
||||
self.heartbeater = TeethAgentHeartbeater(self)
|
||||
self.hardware = hardware.load_hardware_manager()
|
||||
self.hardware = hardware.get_manager()
|
||||
self.command_lock = threading.Lock()
|
||||
self.log = structlog.get_logger()
|
||||
self.started_at = None
|
||||
@ -235,7 +235,7 @@ def build_agent(api_url,
|
||||
if not listen_host:
|
||||
listen_host = advertise_host
|
||||
|
||||
mac_addr = hardware.load_hardware_manager().get_primary_mac_address()
|
||||
mac_addr = hardware.get_manager().get_primary_mac_address()
|
||||
api_client = overlord_agent_api.APIClient(api_url)
|
||||
|
||||
log.info('fetching agent configuration from API',
|
||||
|
@ -44,6 +44,10 @@ class HardwareManager(object):
|
||||
def get_primary_mac_address(self):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_os_install_device(self):
|
||||
pass
|
||||
|
||||
|
||||
class GenericHardwareManager(HardwareManager):
|
||||
def evaluate_hardware_support(cls):
|
||||
@ -52,6 +56,9 @@ class GenericHardwareManager(HardwareManager):
|
||||
def get_primary_mac_address(self):
|
||||
return open('/sys/class/net/eth0/address', 'r').read().strip('\n')
|
||||
|
||||
def get_os_install_device(self):
|
||||
return '/dev/sda'
|
||||
|
||||
|
||||
def _compare_extensions(ext1, ext2):
|
||||
mgr1 = ext1.obj
|
||||
@ -59,20 +66,26 @@ def _compare_extensions(ext1, ext2):
|
||||
return mgr1.evaluate_hardware_support() - mgr2.evaluate_hardware_support()
|
||||
|
||||
|
||||
def load_hardware_manager():
|
||||
log = structlog.get_logger()
|
||||
extension_manager = stevedore.ExtensionManager(
|
||||
namespace='teeth_agent.hardware_managers',
|
||||
invoke_on_load=True)
|
||||
def get_manager():
|
||||
global _global_manager
|
||||
|
||||
# There will always be at least one extension available (the
|
||||
# GenericHardwareManager).
|
||||
preferred_extension = sorted(extension_manager, _compare_extensions)[0]
|
||||
preferred_manager = preferred_extension.obj
|
||||
if not _global_manager:
|
||||
log = structlog.get_logger()
|
||||
extension_manager = stevedore.ExtensionManager(
|
||||
namespace='teeth_agent.hardware_managers',
|
||||
invoke_on_load=True)
|
||||
|
||||
if preferred_manager.evaluate_hardware_support() <= 0:
|
||||
raise RuntimeError('No suitable HardwareManager could be found')
|
||||
# There will always be at least one extension available (the
|
||||
# GenericHardwareManager).
|
||||
preferred_extension = sorted(extension_manager, _compare_extensions)[0]
|
||||
preferred_manager = preferred_extension.obj
|
||||
|
||||
log.info('selected hardware manager',
|
||||
manager_name=preferred_extension.entry_point_target)
|
||||
return preferred_manager
|
||||
if preferred_manager.evaluate_hardware_support() <= 0:
|
||||
raise RuntimeError('No suitable HardwareManager could be found')
|
||||
|
||||
log.info('selected hardware manager',
|
||||
manager_name=preferred_extension.entry_point_target)
|
||||
|
||||
_global_manager = preferred_manager
|
||||
|
||||
return _global_manager
|
||||
|
@ -23,6 +23,7 @@ import requests
|
||||
from teeth_agent import base
|
||||
from teeth_agent import configdrive
|
||||
from teeth_agent import errors
|
||||
from teeth_agent import hardware
|
||||
|
||||
|
||||
def _configdrive_location():
|
||||
@ -114,7 +115,7 @@ class PrepareImageCommand(base.AsyncCommandResult):
|
||||
location = _configdrive_location()
|
||||
metadata = self.command_params['metadata']
|
||||
files = self.command_params['files']
|
||||
device = '/dev/sda'
|
||||
device = hardware.get_manager().get_os_install_device()
|
||||
|
||||
_download_image(image_info)
|
||||
configdrive.write_configdrive(location, metadata, files)
|
||||
|
@ -25,7 +25,7 @@ class TestGenericHardwareManager(unittest.TestCase):
|
||||
self.hardware = hardware.GenericHardwareManager()
|
||||
|
||||
@mock.patch('__builtin__.open')
|
||||
def test_decom_mode(self, mocked_open):
|
||||
def test_get_primary_mac_address(self, mocked_open):
|
||||
f = mocked_open.return_value
|
||||
f.read.return_value = '00:0c:29:8c:11:b1\n'
|
||||
|
||||
@ -34,3 +34,6 @@ class TestGenericHardwareManager(unittest.TestCase):
|
||||
|
||||
mocked_open.assert_called_once_with('/sys/class/net/eth0/address', 'r')
|
||||
f.read.assert_called_once_with()
|
||||
|
||||
def test_get_os_install_device(self):
|
||||
self.assertEqual(self.hardware.get_os_install_device(), '/dev/sda')
|
||||
|
Loading…
x
Reference in New Issue
Block a user