Пример #1
0
 def serialize(self):
     """Turn the status into a dict."""
     return utils.get_ordereddict([
         ('mode', self.mode),
         ('started_at', self.started_at),
         ('version', self.version),
     ])
Пример #2
0
 def serialize(self):
     """Turn a RESTError into a dict."""
     return utils.get_ordereddict([
         ('type', self.__class__.__name__),
         ('code', self.status_code),
         ('message', self.message),
         ('details', self.details),
     ])
Пример #3
0
    def test_write_with_files(self, open_mock, makedirs_mock):
        metadata = {'admin_pass': '******', 'hostname': 'test'}
        for k, v in metadata.iteritems():
            self.writer.add_metadata(k, v)
        files = utils.get_ordereddict([
            ('/etc/conf0', 'contents0'),
            ('/etc/conf1', 'contents1'),
        ])
        for path, contents in files.iteritems():
            self.writer.add_file(path, contents)

        open_mock.return_value.__enter__ = lambda s: s
        open_mock.return_value.__exit__ = mock.Mock()
        write_mock = open_mock.return_value.write

        metadata = self.writer.metadata
        metadata['files'] = [
            {'content_path': '/content/0000', 'path': '/etc/conf0'},
            {'content_path': '/content/0001', 'path': '/etc/conf1'},
        ]

        self.writer.write('/lol', prefix='openstack', version='latest')

        # have to pull out the JSON passed to write and parse it
        # because arbitrary dictionary ordering, etc
        calls = write_mock.mock_calls
        json_data = calls[-1][1][0]
        data = json.loads(json_data)
        self.assertEqual(data, metadata)

        open_calls = [
            mock.call('/lol/openstack/content/0000', 'wb'),
            mock.call().write('contents0'),
            mock.call().__exit__(None, None, None),
            mock.call('/lol/openstack/content/0001', 'wb'),
            mock.call().write('contents1'),
            mock.call().__exit__(None, None, None),
            mock.call('/lol/openstack/latest/meta_data.json', 'wb'),
            # already checked
            mock.call().write(mock.ANY),
            mock.call().__exit__(None, None, None),
        ]
        self.assertEqual(open_mock.mock_calls, open_calls)

        makedirs_calls = [
            mock.call('/lol/openstack/latest'),
            mock.call('/lol/openstack/content')
        ]
        self.assertEqual(makedirs_calls, makedirs_mock.call_args_list)
Пример #4
0
    def test_write_with_files(self, open_mock, makedirs_mock):
        metadata = {'admin_pass': '******', 'hostname': 'test'}
        for k, v in metadata.items():
            self.writer.add_metadata(k, v)
        files = utils.get_ordereddict([
            ('/etc/conf0', 'contents0'),
            ('/etc/conf1', 'contents1'),
        ])
        for path, contents in files.items():
            self.writer.add_file(path, contents)

        open_mock.return_value.__enter__ = lambda s: s
        open_mock.return_value.__exit__ = mock.Mock()
        write_mock = open_mock.return_value.write

        metadata = self.writer.metadata
        metadata['files'] = [
            {'content_path': '/content/0000', 'path': '/etc/conf0'},
            {'content_path': '/content/0001', 'path': '/etc/conf1'},
        ]

        self.writer.write('/lol', prefix='openstack', version='latest')

        # have to pull out the JSON passed to write and parse it
        # because arbitrary dictionary ordering, etc
        calls = write_mock.mock_calls
        json_data = calls[-1][1][0]
        data = json.loads(json_data)
        self.assertEqual(data, metadata)

        open_calls = [
            mock.call('/lol/openstack/content/0000', 'wb'),
            mock.call().write('contents0'),
            mock.call().__exit__(None, None, None),
            mock.call('/lol/openstack/content/0001', 'wb'),
            mock.call().write('contents1'),
            mock.call().__exit__(None, None, None),
            mock.call('/lol/openstack/latest/meta_data.json', 'wb'),
            # already checked
            mock.call().write(mock.ANY),
            mock.call().__exit__(None, None, None),
        ]
        self.assertEqual(open_mock.mock_calls, open_calls)

        makedirs_calls = [
            mock.call('/lol/openstack/latest'),
            mock.call('/lol/openstack/content')
        ]
        self.assertEqual(makedirs_calls, makedirs_mock.call_args_list)
Пример #5
0
 def __init__(self, api_url, advertise_address, listen_address):
     self.api_url = api_url
     self.api_client = ironic_api_client.APIClient(self.api_url)
     self.listen_address = listen_address
     self.advertise_address = advertise_address
     self.mode_implementation = None
     self.version = pkg_resources.get_distribution('ironic-python-agent')\
         .version
     self.api = app.VersionSelectorApplication(self)
     self.command_results = utils.get_ordereddict()
     self.heartbeater = IronicPythonAgentHeartbeater(self)
     self.heartbeat_timeout = None
     self.hardware = hardware.get_manager()
     self.command_lock = threading.Lock()
     self.log = log.getLogger(__name__)
     self.started_at = None
     self.node = None
Пример #6
0
 def __init__(self):
     self.command_lock = threading.Lock()
     self.command_results = utils.get_ordereddict()
     self.ext_mgr = None
Пример #7
0
 def __init__(self):
     self.command_lock = threading.Lock()
     self.command_results = utils.get_ordereddict()
     self.ext_mgr = None
Пример #8
0
 def __init__(self):
     self.metadata = {}
     self.files = utils.get_ordereddict()
Пример #9
0
 def serialize(self):
     return utils.get_ordereddict([
         ('type', self.type),
         ('id', self.id),
     ])