s/onset_files/injected_files/g
This commit is contained in:
parent
1d69d49912
commit
e9ef6e0478
|
@ -169,7 +169,7 @@ class Controller(wsgi.Controller):
|
|||
metadata.append({'key': k, 'value': v})
|
||||
|
||||
personality = env['server'].get('personality', [])
|
||||
onset_files = self._get_onset_files(personality)
|
||||
injected_files = self._get_injected_files(personality)
|
||||
|
||||
try:
|
||||
instances = self.compute_api.create(
|
||||
|
@ -183,7 +183,7 @@ class Controller(wsgi.Controller):
|
|||
key_name=key_pair['name'],
|
||||
key_data=key_pair['public_key'],
|
||||
metadata=metadata,
|
||||
onset_files=onset_files)
|
||||
injected_files=injected_files)
|
||||
except QuotaError as error:
|
||||
self._handle_quota_error(error)
|
||||
|
||||
|
@ -207,15 +207,15 @@ class Controller(wsgi.Controller):
|
|||
else:
|
||||
return self._deserialize(request.body, request.get_content_type())
|
||||
|
||||
def _get_onset_files(self, personality):
|
||||
def _get_injected_files(self, personality):
|
||||
"""
|
||||
Create a list of onset files from the personality attribute
|
||||
Create a list of injected files from the personality attribute
|
||||
|
||||
At this time, onset_files must be formatted as a list of
|
||||
At this time, injected_files must be formatted as a list of
|
||||
(file_path, file_content) pairs for compatibility with the
|
||||
underlying compute service.
|
||||
"""
|
||||
onset_files = []
|
||||
injected_files = []
|
||||
for item in personality:
|
||||
try:
|
||||
path = item['path']
|
||||
|
@ -230,8 +230,8 @@ class Controller(wsgi.Controller):
|
|||
except TypeError:
|
||||
msg = 'Personality content for %s cannot be decoded' % path
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
onset_files.append((path, contents))
|
||||
return onset_files
|
||||
injected_files.append((path, contents))
|
||||
return injected_files
|
||||
|
||||
def _handle_quota_errors(self, error):
|
||||
"""
|
||||
|
|
|
@ -80,20 +80,20 @@ class API(base.Base):
|
|||
topic,
|
||||
{"method": "get_network_topic", "args": {'fake': 1}})
|
||||
|
||||
def _check_onset_file_quota(self, context, onset_files):
|
||||
def _check_injected_file_quota(self, context, injected_files):
|
||||
"""
|
||||
Enforce quota limits on onset files
|
||||
Enforce quota limits on injected files
|
||||
|
||||
Raises a QuotaError if any limit is exceeded
|
||||
"""
|
||||
if onset_files is None:
|
||||
if injected_files is None:
|
||||
return
|
||||
limit = quota.allowed_onset_files(context)
|
||||
if len(onset_files) > limit:
|
||||
limit = quota.allowed_injected_files(context)
|
||||
if len(injected_files) > limit:
|
||||
raise quota.QuotaError(code="OnsetFileLimitExceeded")
|
||||
path_limit = quota.allowed_onset_file_path_bytes(context)
|
||||
content_limit = quota.allowed_onset_file_content_bytes(context)
|
||||
for path, content in onset_files:
|
||||
path_limit = quota.allowed_injected_file_path_bytes(context)
|
||||
content_limit = quota.allowed_injected_file_content_bytes(context)
|
||||
for path, content in injected_files:
|
||||
if len(path) > path_limit:
|
||||
raise quota.QuotaError(code="OnsetFilePathLimitExceeded")
|
||||
if len(content) > content_limit:
|
||||
|
@ -105,7 +105,7 @@ class API(base.Base):
|
|||
display_name='', display_description='',
|
||||
key_name=None, key_data=None, security_group='default',
|
||||
availability_zone=None, user_data=None, metadata=[],
|
||||
onset_files=None):
|
||||
injected_files=None):
|
||||
"""Create the number of instances requested if quota and
|
||||
other arguments check out ok."""
|
||||
|
||||
|
@ -143,7 +143,7 @@ class API(base.Base):
|
|||
LOG.warn(msg)
|
||||
raise quota.QuotaError(msg, "MetadataLimitExceeded")
|
||||
|
||||
self._check_onset_file_quota(context, onset_files)
|
||||
self._check_injected_file_quota(context, injected_files)
|
||||
|
||||
image = self.image_service.show(context, image_id)
|
||||
|
||||
|
@ -246,7 +246,7 @@ class API(base.Base):
|
|||
"args": {"topic": FLAGS.compute_topic,
|
||||
"instance_id": instance_id,
|
||||
"availability_zone": availability_zone,
|
||||
"onset_files": onset_files}})
|
||||
"injected_files": injected_files}})
|
||||
|
||||
for group_id in security_groups:
|
||||
self.trigger_security_group_members_refresh(elevated, group_id)
|
||||
|
|
|
@ -179,7 +179,7 @@ class ComputeManager(manager.Manager):
|
|||
"""Launch a new instance with specified options."""
|
||||
context = context.elevated()
|
||||
instance_ref = self.db.instance_get(context, instance_id)
|
||||
instance_ref.onset_files = kwargs.get('onset_files', [])
|
||||
instance_ref.injected_files = kwargs.get('injected_files', [])
|
||||
if instance_ref['name'] in self.driver.list_instances():
|
||||
raise exception.Error(_("Instance has already been created"))
|
||||
LOG.audit(_("instance %s: starting..."), instance_id,
|
||||
|
|
|
@ -161,7 +161,7 @@ class Certificate(BASE, NovaBase):
|
|||
class Instance(BASE, NovaBase):
|
||||
"""Represents a guest vm."""
|
||||
__tablename__ = 'instances'
|
||||
onset_files = []
|
||||
injected_files = []
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
|
|
|
@ -37,12 +37,12 @@ flags.DEFINE_integer('quota_floating_ips', 10,
|
|||
'number of floating ips allowed per project')
|
||||
flags.DEFINE_integer('quota_metadata_items', 128,
|
||||
'number of metadata items allowed per instance')
|
||||
flags.DEFINE_integer('quota_max_onset_files', 5,
|
||||
'number of onset files allowed')
|
||||
flags.DEFINE_integer('quota_max_onset_file_content_bytes', 10 * 1024,
|
||||
'number of bytes allowed per onset file')
|
||||
flags.DEFINE_integer('quota_max_onset_file_path_bytes', 255,
|
||||
'number of bytes allowed per onset file path')
|
||||
flags.DEFINE_integer('quota_max_injected_files', 5,
|
||||
'number of injected files allowed')
|
||||
flags.DEFINE_integer('quota_max_injected_file_content_bytes', 10 * 1024,
|
||||
'number of bytes allowed per injected file')
|
||||
flags.DEFINE_integer('quota_max_injected_file_path_bytes', 255,
|
||||
'number of bytes allowed per injected file path')
|
||||
|
||||
|
||||
def get_quota(context, project_id):
|
||||
|
@ -113,19 +113,19 @@ def allowed_metadata_items(context, num_metadata_items):
|
|||
return min(num_metadata_items, num_allowed_metadata_items)
|
||||
|
||||
|
||||
def allowed_onset_files(context):
|
||||
"""Return the number of onset files allowed"""
|
||||
return int(FLAGS.quota_max_onset_files)
|
||||
def allowed_injected_files(context):
|
||||
"""Return the number of injected files allowed"""
|
||||
return FLAGS.quota_max_injected_files
|
||||
|
||||
|
||||
def allowed_onset_file_content_bytes(context):
|
||||
"""Return the number of bytes allowed per onset file content"""
|
||||
return int(FLAGS.quota_max_onset_file_content_bytes)
|
||||
def allowed_injected_file_content_bytes(context):
|
||||
"""Return the number of bytes allowed per injected file content"""
|
||||
return FLAGS.quota_max_injected_file_content_bytes
|
||||
|
||||
|
||||
def allowed_onset_file_path_bytes(context):
|
||||
"""Return the number of bytes allowed in an onset file path"""
|
||||
return int(FLAGS.quota_max_onset_file_path_bytes)
|
||||
def allowed_injected_file_path_bytes(context):
|
||||
"""Return the number of bytes allowed in an injected file path"""
|
||||
return FLAGS.quota_max_injected_file_path_bytes
|
||||
|
||||
|
||||
class QuotaError(exception.ApiError):
|
||||
|
|
|
@ -834,13 +834,13 @@ class TestServerInstanceCreation(test.TestCase):
|
|||
class MockComputeAPI(object):
|
||||
|
||||
def __init__(self):
|
||||
self.onset_files = None
|
||||
self.injected_files = None
|
||||
|
||||
def create(self, *args, **kwargs):
|
||||
if 'onset_files' in kwargs:
|
||||
self.onset_files = kwargs['onset_files']
|
||||
if 'injected_files' in kwargs:
|
||||
self.injected_files = kwargs['injected_files']
|
||||
else:
|
||||
self.onset_files = None
|
||||
self.injected_files = None
|
||||
return [{'id': '1234', 'display_name': 'fakeinstance'}]
|
||||
|
||||
def set_admin_password(self, *args, **kwargs):
|
||||
|
@ -920,46 +920,46 @@ class TestServerInstanceCreation(test.TestCase):
|
|||
request = self._get_create_request_json(body_dict)
|
||||
compute_api, response = \
|
||||
self._run_create_instance_with_mock_compute_api(request)
|
||||
return request, response, compute_api.onset_files
|
||||
return request, response, compute_api.injected_files
|
||||
|
||||
def _create_instance_with_personality_xml(self, personality):
|
||||
body_dict = self._create_personality_request_dict(personality)
|
||||
request = self._get_create_request_xml(body_dict)
|
||||
compute_api, response = \
|
||||
self._run_create_instance_with_mock_compute_api(request)
|
||||
return request, response, compute_api.onset_files
|
||||
return request, response, compute_api.injected_files
|
||||
|
||||
def test_create_instance_with_no_personality(self):
|
||||
request, response, onset_files = \
|
||||
request, response, injected_files = \
|
||||
self._create_instance_with_personality_json(personality=None)
|
||||
self.assertEquals(response.status_int, 200)
|
||||
self.assertEquals(onset_files, [])
|
||||
self.assertEquals(injected_files, [])
|
||||
|
||||
def test_create_instance_with_no_personality_xml(self):
|
||||
request, response, onset_files = \
|
||||
request, response, injected_files = \
|
||||
self._create_instance_with_personality_xml(personality=None)
|
||||
self.assertEquals(response.status_int, 200)
|
||||
self.assertEquals(onset_files, [])
|
||||
self.assertEquals(injected_files, [])
|
||||
|
||||
def test_create_instance_with_personality(self):
|
||||
path = '/my/file/path'
|
||||
contents = '#!/bin/bash\necho "Hello, World!"\n'
|
||||
b64contents = base64.b64encode(contents)
|
||||
personality = [(path, b64contents)]
|
||||
request, response, onset_files = \
|
||||
request, response, injected_files = \
|
||||
self._create_instance_with_personality_json(personality)
|
||||
self.assertEquals(response.status_int, 200)
|
||||
self.assertEquals(onset_files, [(path, contents)])
|
||||
self.assertEquals(injected_files, [(path, contents)])
|
||||
|
||||
def test_create_instance_with_personality_xml(self):
|
||||
path = '/my/file/path'
|
||||
contents = '#!/bin/bash\necho "Hello, World!"\n'
|
||||
b64contents = base64.b64encode(contents)
|
||||
personality = [(path, b64contents)]
|
||||
request, response, onset_files = \
|
||||
request, response, injected_files = \
|
||||
self._create_instance_with_personality_xml(personality)
|
||||
self.assertEquals(response.status_int, 200)
|
||||
self.assertEquals(onset_files, [(path, contents)])
|
||||
self.assertEquals(injected_files, [(path, contents)])
|
||||
|
||||
def test_create_instance_with_personality_no_path(self):
|
||||
personality = [('/remove/this/path',
|
||||
|
@ -970,7 +970,7 @@ class TestServerInstanceCreation(test.TestCase):
|
|||
compute_api, response = \
|
||||
self._run_create_instance_with_mock_compute_api(request)
|
||||
self.assertEquals(response.status_int, 400)
|
||||
self.assertEquals(compute_api.onset_files, None)
|
||||
self.assertEquals(compute_api.injected_files, None)
|
||||
|
||||
def _test_create_instance_with_personality_no_path_xml(self):
|
||||
personality = [('/remove/this/path',
|
||||
|
@ -981,7 +981,7 @@ class TestServerInstanceCreation(test.TestCase):
|
|||
compute_api, response = \
|
||||
self._run_create_instance_with_mock_compute_api(request)
|
||||
self.assertEquals(response.status_int, 400)
|
||||
self.assertEquals(compute_api.onset_files, None)
|
||||
self.assertEquals(compute_api.injected_files, None)
|
||||
|
||||
def test_create_instance_with_personality_no_contents(self):
|
||||
personality = [('/test/path',
|
||||
|
@ -992,7 +992,7 @@ class TestServerInstanceCreation(test.TestCase):
|
|||
compute_api, response = \
|
||||
self._run_create_instance_with_mock_compute_api(request)
|
||||
self.assertEquals(response.status_int, 400)
|
||||
self.assertEquals(compute_api.onset_files, None)
|
||||
self.assertEquals(compute_api.injected_files, None)
|
||||
|
||||
def test_create_instance_with_personality_not_a_list(self):
|
||||
personality = [('/test/path', base64.b64encode('test\ncontents\n'))]
|
||||
|
@ -1003,16 +1003,16 @@ class TestServerInstanceCreation(test.TestCase):
|
|||
compute_api, response = \
|
||||
self._run_create_instance_with_mock_compute_api(request)
|
||||
self.assertEquals(response.status_int, 400)
|
||||
self.assertEquals(compute_api.onset_files, None)
|
||||
self.assertEquals(compute_api.injected_files, None)
|
||||
|
||||
def test_create_instance_with_personality_with_non_b64_content(self):
|
||||
path = '/my/file/path'
|
||||
contents = '#!/bin/bash\necho "Oh no!"\n'
|
||||
personality = [(path, contents)]
|
||||
request, response, onset_files = \
|
||||
request, response, injected_files = \
|
||||
self._create_instance_with_personality_json(personality)
|
||||
self.assertEquals(response.status_int, 400)
|
||||
self.assertEquals(onset_files, None)
|
||||
self.assertEquals(injected_files, None)
|
||||
|
||||
def test_create_instance_with_three_personalities(self):
|
||||
files = [
|
||||
|
@ -1023,19 +1023,19 @@ class TestServerInstanceCreation(test.TestCase):
|
|||
personality = []
|
||||
for path, content in files:
|
||||
personality.append((path, base64.b64encode(content)))
|
||||
request, response, onset_files = \
|
||||
request, response, injected_files = \
|
||||
self._create_instance_with_personality_json(personality)
|
||||
self.assertEquals(response.status_int, 200)
|
||||
self.assertEquals(onset_files, files)
|
||||
self.assertEquals(injected_files, files)
|
||||
|
||||
def test_create_instance_personality_empty_content(self):
|
||||
path = '/my/file/path'
|
||||
contents = ''
|
||||
personality = [(path, contents)]
|
||||
request, response, onset_files = \
|
||||
request, response, injected_files = \
|
||||
self._create_instance_with_personality_json(personality)
|
||||
self.assertEquals(response.status_int, 200)
|
||||
self.assertEquals(onset_files, [(path, contents)])
|
||||
self.assertEquals(injected_files, [(path, contents)])
|
||||
|
||||
def test_create_instance_admin_pass_json(self):
|
||||
request, response, dummy = \
|
||||
|
|
|
@ -200,66 +200,66 @@ class QuotaTestCase(test.TestCase):
|
|||
image_id='fake',
|
||||
metadata=metadata)
|
||||
|
||||
def test_allowed_onset_files(self):
|
||||
def test_allowed_injected_files(self):
|
||||
self.assertEqual(
|
||||
quota.allowed_onset_files(self.context),
|
||||
FLAGS.quota_max_onset_files)
|
||||
quota.allowed_injected_files(self.context),
|
||||
FLAGS.quota_max_injected_files)
|
||||
|
||||
def _create_with_onset_files(self, files):
|
||||
def _create_with_injected_files(self, files):
|
||||
api = compute.API(image_service=self.StubImageService())
|
||||
api.create(self.context, min_count=1, max_count=1,
|
||||
instance_type='m1.small', image_id='fake',
|
||||
onset_files=files)
|
||||
injected_files=files)
|
||||
|
||||
def test_no_onset_files(self):
|
||||
def test_no_injected_files(self):
|
||||
api = compute.API(image_service=self.StubImageService())
|
||||
api.create(self.context, instance_type='m1.small', image_id='fake')
|
||||
|
||||
def test_max_onset_files(self):
|
||||
def test_max_injected_files(self):
|
||||
files = []
|
||||
for i in xrange(FLAGS.quota_max_onset_files):
|
||||
for i in xrange(FLAGS.quota_max_injected_files):
|
||||
files.append(('/my/path%d' % i, 'config = test\n'))
|
||||
self._create_with_onset_files(files) # no QuotaError
|
||||
self._create_with_injected_files(files) # no QuotaError
|
||||
|
||||
def test_too_many_onset_files(self):
|
||||
def test_too_many_injected_files(self):
|
||||
files = []
|
||||
for i in xrange(FLAGS.quota_max_onset_files + 1):
|
||||
for i in xrange(FLAGS.quota_max_injected_files + 1):
|
||||
files.append(('/my/path%d' % i, 'my\ncontent%d\n' % i))
|
||||
self.assertRaises(quota.QuotaError,
|
||||
self._create_with_onset_files, files)
|
||||
self._create_with_injected_files, files)
|
||||
|
||||
def test_allowed_onset_file_content_bytes(self):
|
||||
def test_allowed_injected_file_content_bytes(self):
|
||||
self.assertEqual(
|
||||
quota.allowed_onset_file_content_bytes(self.context),
|
||||
FLAGS.quota_max_onset_file_content_bytes)
|
||||
quota.allowed_injected_file_content_bytes(self.context),
|
||||
FLAGS.quota_max_injected_file_content_bytes)
|
||||
|
||||
def test_max_onset_file_content_bytes(self):
|
||||
max = FLAGS.quota_max_onset_file_content_bytes
|
||||
def test_max_injected_file_content_bytes(self):
|
||||
max = FLAGS.quota_max_injected_file_content_bytes
|
||||
content = ''.join(['a' for i in xrange(max)])
|
||||
files = [('/test/path', content)]
|
||||
self._create_with_onset_files(files) # no QuotaError
|
||||
self._create_with_injected_files(files) # no QuotaError
|
||||
|
||||
def test_too_many_onset_file_content_bytes(self):
|
||||
max = FLAGS.quota_max_onset_file_content_bytes
|
||||
def test_too_many_injected_file_content_bytes(self):
|
||||
max = FLAGS.quota_max_injected_file_content_bytes
|
||||
content = ''.join(['a' for i in xrange(max + 1)])
|
||||
files = [('/test/path', content)]
|
||||
self.assertRaises(quota.QuotaError,
|
||||
self._create_with_onset_files, files)
|
||||
self._create_with_injected_files, files)
|
||||
|
||||
def test_allowed_onset_file_path_bytes(self):
|
||||
def test_allowed_injected_file_path_bytes(self):
|
||||
self.assertEqual(
|
||||
quota.allowed_onset_file_path_bytes(self.context),
|
||||
FLAGS.quota_max_onset_file_path_bytes)
|
||||
quota.allowed_injected_file_path_bytes(self.context),
|
||||
FLAGS.quota_max_injected_file_path_bytes)
|
||||
|
||||
def test_max_onset_file_path_bytes(self):
|
||||
max = FLAGS.quota_max_onset_file_path_bytes
|
||||
def test_max_injected_file_path_bytes(self):
|
||||
max = FLAGS.quota_max_injected_file_path_bytes
|
||||
path = ''.join(['a' for i in xrange(max)])
|
||||
files = [(path, 'config = quotatest')]
|
||||
self._create_with_onset_files(files) # no QuotaError
|
||||
self._create_with_injected_files(files) # no QuotaError
|
||||
|
||||
def test_too_many_onset_file_path_bytes(self):
|
||||
max = FLAGS.quota_max_onset_file_path_bytes
|
||||
def test_too_many_injected_file_path_bytes(self):
|
||||
max = FLAGS.quota_max_injected_file_path_bytes
|
||||
path = ''.join(['a' for i in xrange(max + 1)])
|
||||
files = [(path, 'config = quotatest')]
|
||||
self.assertRaises(quota.QuotaError,
|
||||
self._create_with_onset_files, files)
|
||||
self._create_with_injected_files, files)
|
||||
|
|
|
@ -137,19 +137,20 @@ class VMOps(object):
|
|||
LOG.info(_('Spawning VM %(instance_name)s created %(vm_ref)s.')
|
||||
% locals())
|
||||
|
||||
def _inject_onset_files():
|
||||
onset_files = instance.onset_files
|
||||
if onset_files:
|
||||
def _inject_files():
|
||||
injected_files = instance.injected_files
|
||||
if injected_files:
|
||||
# Check if this is a JSON-encoded string and convert if needed.
|
||||
if isinstance(onset_files, basestring):
|
||||
if isinstance(injected_files, basestring):
|
||||
try:
|
||||
onset_files = json.loads(onset_files)
|
||||
injected_files = json.loads(injected_files)
|
||||
except ValueError:
|
||||
LOG.exception(_("Invalid value for onset_files: '%s'")
|
||||
% onset_files)
|
||||
onset_files = []
|
||||
LOG.exception(
|
||||
_("Invalid value for injected_files: '%s'")
|
||||
% injected_files)
|
||||
injected_files = []
|
||||
# Inject any files, if specified
|
||||
for path, contents in instance.onset_files:
|
||||
for path, contents in instance.injected_files:
|
||||
LOG.debug(_("Injecting file path: '%s'") % path)
|
||||
self.inject_file(instance, path, contents)
|
||||
# NOTE(armando): Do we really need to do this in virt?
|
||||
|
@ -165,7 +166,7 @@ class VMOps(object):
|
|||
if state == power_state.RUNNING:
|
||||
LOG.debug(_('Instance %s: booted'), instance_name)
|
||||
timer.stop()
|
||||
_inject_onset_files()
|
||||
_inject_files()
|
||||
return True
|
||||
except Exception, exc:
|
||||
LOG.warn(exc)
|
||||
|
|
Loading…
Reference in New Issue