Change runtime to string type

The container create parameter `runtime` can be any string like
`runc`; `cor`, `clear` or any value configured in the docker
configuration file. So this patch changes its type from enum
to string.

Change-Id: Ia360f16edacf352e538a0056af0e3683a21c0053
Partial-Implements: blueprint support-secure-container
This commit is contained in:
Madhuri Kumari 2017-09-08 12:30:16 +05:30
parent a7c1957501
commit aa3c5f1506
10 changed files with 11 additions and 47 deletions

View File

@ -248,8 +248,9 @@ restart_policy:
type: string
runtime:
description: |
The container runtime tool to create container with. Allowed values
are runc.
The container runtime tool to create container with. You can use
the default runtime that is `runc` or any other runtime configured
to use with Docker.
in: body
type: string
security_groups:

View File

@ -38,9 +38,3 @@ RESOURCE_CLASSES = (
'NUMA_SOCKET', 'NUMA_CORE', 'NUMA_THREAD', 'NUMA_MEMORY_MB',
'IPV4_ADDRESS'
)
CONTAINER_RUNTIME = (
RUNC,
) = (
'runc',
)

View File

@ -124,7 +124,6 @@ environment = {
runtime = {
'type': ['string', 'null'],
'enum': ['runc', None]
}
image_id = {

View File

@ -48,8 +48,8 @@ a set of high-coupled containers into a unit. If set to False, infra container
won't be created.
"""),
cfg.StrOpt('container_runtime', default='runc',
help="""Define the runtime to create container with. Current
supported values in Zun is ``runc``.""")
help="""Define the runtime to create container with. Default value
in Zun is ``runc``.""")
]

View File

@ -39,7 +39,8 @@ class Container(base.ZunPersistentObject, base.ZunObject):
# Version 1.17: Add security_groups
# Version 1.18: Add auto_remove
# Version 1.19: Add runtime column
VERSION = '1.19'
# Version 1.20: Change runtime to String type
VERSION = '1.20'
fields = {
'id': fields.IntegerField(),
@ -72,7 +73,7 @@ class Container(base.ZunPersistentObject, base.ZunObject):
'websocket_url': fields.StringField(nullable=True),
'websocket_token': fields.StringField(nullable=True),
'security_groups': fields.ListOfStringsField(nullable=True),
'runtime': z_fields.ContainerRuntimeField(nullable=True)
'runtime': fields.StringField(nullable=True)
}
@staticmethod

View File

@ -76,15 +76,3 @@ class ResourceClass(fields.Enum):
class ResourceClassField(fields.AutoTypedField):
AUTO_TYPE = ResourceClass()
class ContainerRuntime(fields.Enum):
ALL = consts.CONTAINER_RUNTIME
def __init__(self):
super(ContainerRuntime, self).__init__(
valid_values=ContainerRuntime.ALL)
class ContainerRuntimeField(fields.BaseEnumField):
AUTO_TYPE = ContainerRuntime()

View File

@ -98,7 +98,7 @@ class TestContainerController(api_base.FunctionalTest):
params = ('{"name": "MyDocker", "image": "ubuntu",'
'"command": "env", "memory": "512",'
'"environment": {"key1": "val1", "key2": "val2"},'
'"runtime": "wrong_value"}')
'"runtime": 1234}')
api_version = {"OpenStack-API-Version": CURRENT_VERSION}
with self.assertRaisesRegex(AppError,
"Invalid input for field"):

View File

@ -189,7 +189,7 @@ class TestSchemaValidations(base.BaseTestCase):
def test_create_schema_wrong_runtime(self):
request_to_validate = {'image': 'nginx',
'runtime': 'invalid'}
'runtime': 123}
with self.assertRaisesRegex(exception.SchemaValidationError,
"Invalid input for field"
" 'runtime'"):

View File

@ -87,22 +87,3 @@ class TestResourceClass(test_fields.TestField):
def test_stringify_invalid(self):
self.assertRaises(ValueError, self.field.stringify, 'bad_value')
class TestContainerRuntime(test_fields.TestField):
def setUp(self):
super(TestContainerRuntime, self).setUp()
self.field = fields.ContainerRuntime()
self.coerce_good_values = [
('runc', 'runc'),
]
self.coerce_bad_values = ['bad_value']
self.to_primitive_values = self.coerce_good_values[0:1]
self.from_primitive_values = self.coerce_good_values[0:1]
def test_stringify(self):
self.assertEqual("'runc'",
self.field.stringify('runc'))
def test_stringify_invalid(self):
self.assertRaises(ValueError, self.field.stringify, 'bad_value')

View File

@ -344,7 +344,7 @@ class TestObject(test_base.TestCase, _TestObject):
# For more information on object version testing, read
# https://docs.openstack.org/zun/latest/
object_data = {
'Container': '1.19-5f8a734d3b0cc2a47f48205944672ab5',
'Container': '1.20-e77b5c44456e607a3b1752c44dcc827e',
'VolumeMapping': '1.0-187aeb163610315595be729df1c642fc',
'Image': '1.0-0b976be24f4f6ee0d526e5c981ce0633',
'MyObj': '1.0-34c4b1aadefd177b13f9a2f894cc23cd',