blob: 4dde349ae46286c07aff86c2df17455d6a0508ab [file] [log] [blame]
Matteo Scandolo431781c2017-09-06 15:33:07 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
17import unittest
18
19import yaml
20from xosgenx.generator import XOSGenerator
21from helpers import FakeArgs
22
23class Args:
24 pass
25
26class XOSGeneratorTest(unittest.TestCase):
27
28 def test_swagger_target(self):
29 """
30 [XOS-GenX] The swagger xtarget should generate the appropriate json
31 """
32 # xosgenx --output . --target xosgenx/targets/swagger.xtarget --write-to-file single --dest-file swagger.yaml ../../xos/core/models/core.xproto
33 # http-server --cors Users/teone/Sites/opencord/orchestration/xos/lib/xos-genx/
34 xproto = \
35 """
36 option app_label = "core";
37
38 message Instance::instance_policy (XOSBase) {
39 option validators = "instance_creator:Instance has no creator, instance_isolation: Container instance {obj.name} must use container image, instance_isolation_container_vm_parent:Container-vm instance {obj.name} must have a parent, instance_parent_isolation_container_vm:Parent field can only be set on Container-vm instances ({obj.name}), instance_isolation_vm: VM Instance {obj.name} must use VM image, instance_creator_privilege: instance creator has no privileges on slice";
40 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
41 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
42 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
43 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
44 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False, gui_hidden = True];
45 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
46 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
47 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
48 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
49 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
50 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
51 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", null = False, db_index = True, blank = False];
52 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True, varchar = True];
53 required string isolation = 14 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False];
54 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
55 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
56 }
57 """
58 args = FakeArgs()
59 args.inputs = xproto
60 args.target = 'swagger.xtarget'
61 args.output = "/Users/teone/Sites/opencord/orchestration/xos/lib/xos-genx"
62 args.write_to_file = "single"
63 args.dest_file = "swagger.yaml"
64 args.quiet = False
65 output = XOSGenerator.generate(args)
66 self.assertEqual(True, False);
67
68if __name__ == '__main__':
69 unittest.main()