occi-core 4.1.3 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +8 -0
  3. data/README.md +49 -17
  4. data/lib/occi/collection.rb +37 -21
  5. data/lib/occi/core/action.rb +5 -5
  6. data/lib/occi/core/action_instance.rb +45 -3
  7. data/lib/occi/core/actions.rb +2 -1
  8. data/lib/occi/core/attributes.rb +253 -73
  9. data/lib/occi/core/categories.rb +1 -0
  10. data/lib/occi/core/category.rb +25 -8
  11. data/lib/occi/core/entities.rb +1 -0
  12. data/lib/occi/core/entity.rb +51 -74
  13. data/lib/occi/core/kind.rb +15 -11
  14. data/lib/occi/core/kinds.rb +1 -1
  15. data/lib/occi/core/link.rb +14 -15
  16. data/lib/occi/core/links.rb +1 -1
  17. data/lib/occi/core/mixin.rb +5 -5
  18. data/lib/occi/core/mixins.rb +2 -2
  19. data/lib/occi/core/properties.rb +90 -12
  20. data/lib/occi/core/resource.rb +7 -3
  21. data/lib/occi/core/resources.rb +2 -2
  22. data/lib/occi/errors/attribute_definitions_converted_error.rb +5 -0
  23. data/lib/occi/errors/attribute_missing_error.rb +5 -0
  24. data/lib/occi/errors/attribute_name_invalid_error.rb +5 -0
  25. data/lib/occi/errors/attribute_not_defined_error.rb +5 -0
  26. data/lib/occi/errors/attribute_property_type_error.rb +5 -0
  27. data/lib/occi/errors/attribute_type_error.rb +5 -0
  28. data/lib/occi/errors/kind_not_defined_error.rb +5 -0
  29. data/lib/occi/errors/parser_input_error.rb +5 -0
  30. data/lib/occi/errors/parser_type_error.rb +5 -0
  31. data/lib/occi/errors.rb +1 -0
  32. data/lib/occi/extensions/hashie.rb +25 -0
  33. data/lib/occi/helpers/comparators/action_instance.rb +22 -0
  34. data/lib/occi/helpers/comparators/attributes.rb +22 -0
  35. data/lib/occi/helpers/comparators/categories.rb +22 -0
  36. data/lib/occi/helpers/comparators/category.rb +22 -0
  37. data/lib/occi/helpers/comparators/collection.rb +40 -0
  38. data/lib/occi/helpers/comparators/entities.rb +22 -0
  39. data/lib/occi/helpers/comparators/entity.rb +22 -0
  40. data/lib/occi/helpers/comparators/properties.rb +26 -0
  41. data/lib/occi/helpers/comparators.rb +1 -0
  42. data/lib/occi/infrastructure/compute.rb +11 -9
  43. data/lib/occi/infrastructure/network.rb +27 -27
  44. data/lib/occi/infrastructure/networkinterface.rb +22 -23
  45. data/lib/occi/infrastructure/os_tpl.rb +1 -1
  46. data/lib/occi/infrastructure/resource_tpl.rb +1 -1
  47. data/lib/occi/infrastructure/storage.rb +7 -6
  48. data/lib/occi/infrastructure/storagelink.rb +4 -4
  49. data/lib/occi/log.rb +13 -10
  50. data/lib/occi/model.rb +9 -8
  51. data/lib/occi/parser/json.rb +11 -9
  52. data/lib/occi/parser/ova.rb +12 -6
  53. data/lib/occi/parser/ovf.rb +173 -116
  54. data/lib/occi/parser/text/constants.rb +87 -0
  55. data/lib/occi/parser/text.rb +161 -200
  56. data/lib/occi/parser/xml.rb +10 -8
  57. data/lib/occi/parser.rb +100 -50
  58. data/lib/occi/settings.rb +2 -1
  59. data/lib/occi/version.rb +1 -1
  60. data/lib/occi-core.rb +6 -4
  61. data/occi-core.gemspec +0 -7
  62. data/spec/occi/collection_samples/collection1.json +1 -0
  63. data/spec/occi/collection_samples/directory2/collection2.json +1 -0
  64. data/spec/occi/collection_spec.rb +961 -31
  65. data/spec/occi/core/action_instance_spec.rb +317 -0
  66. data/spec/occi/core/action_spec.rb +71 -0
  67. data/spec/occi/core/attributes_spec.rb +582 -27
  68. data/spec/occi/core/category_spec.rb +194 -18
  69. data/spec/occi/core/entities_spec.rb +96 -0
  70. data/spec/occi/core/entity_spec.rb +317 -28
  71. data/spec/occi/core/kind_spec.rb +127 -16
  72. data/spec/occi/core/link_spec.rb +35 -0
  73. data/spec/occi/core/links_spec.rb +130 -0
  74. data/spec/occi/core/mixins_spec.rb +107 -0
  75. data/spec/occi/core/properties_spec.rb +167 -0
  76. data/spec/occi/core/resource_spec.rb +23 -9
  77. data/spec/occi/core_spec.rb +12 -0
  78. data/spec/occi/infrastructure/compute_spec.rb +218 -18
  79. data/spec/occi/infrastructure/network_spec.rb +96 -0
  80. data/spec/occi/infrastructure/networkinterface_spec.rb +96 -0
  81. data/spec/occi/infrastructure/storage_spec.rb +33 -0
  82. data/spec/occi/infrastructure/storagelink_spec.rb +45 -0
  83. data/spec/occi/log_spec.rb +104 -1
  84. data/spec/occi/model_spec.rb +251 -39
  85. data/spec/occi/{test.json → parser/json_samples/test.json} +0 -0
  86. data/spec/occi/parser/ova_samples/test.dump +0 -0
  87. data/spec/occi/{test.ova → parser/ova_samples/test.ova} +0 -0
  88. data/spec/occi/parser/ovf_samples/test.dump +0 -0
  89. data/spec/occi/{test.ovf → parser/ovf_samples/test.ovf} +0 -0
  90. data/spec/occi/parser/text_samples/occi_categories.dump +0 -0
  91. data/spec/occi/parser/text_samples/occi_categories.text +2 -0
  92. data/spec/occi/parser/text_samples/occi_compute_rocci_server.dump +0 -0
  93. data/spec/occi/parser/text_samples/occi_compute_rocci_server.resource.dump +0 -0
  94. data/spec/occi/parser/text_samples/occi_compute_rocci_server.text +10 -0
  95. data/spec/occi/parser/text_samples/occi_link_resource_instance.dump +0 -0
  96. data/spec/occi/parser/text_samples/occi_link_resource_instance.text +7 -0
  97. data/spec/occi/parser/text_samples/occi_link_simple.dump +0 -0
  98. data/spec/occi/parser/text_samples/occi_link_simple.link_string.dump +0 -0
  99. data/spec/occi/parser/text_samples/occi_link_simple.text +1 -0
  100. data/spec/occi/parser/text_samples/occi_link_w_attributes.dump +0 -0
  101. data/spec/occi/parser/text_samples/occi_link_w_attributes.text +7 -0
  102. data/spec/occi/parser/text_samples/occi_link_w_category.dump +0 -0
  103. data/spec/occi/parser/text_samples/occi_link_w_category.text +3 -0
  104. data/spec/occi/parser/text_samples/occi_model_rocci_server.dump +0 -0
  105. data/spec/occi/parser/text_samples/occi_model_rocci_server.text +51 -0
  106. data/spec/occi/parser/text_samples/occi_network_rocci_server.dump +0 -0
  107. data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.dump +0 -0
  108. data/spec/occi/parser/text_samples/occi_network_rocci_server.text +11 -0
  109. data/spec/occi/parser/text_samples/occi_resource_w_attributes.dump +0 -0
  110. data/spec/occi/parser/text_samples/occi_resource_w_attributes.text +11 -0
  111. data/spec/occi/parser/text_samples/occi_resource_w_inline_links.dump +0 -0
  112. data/spec/occi/parser/text_samples/occi_resource_w_inline_links.text +16 -0
  113. data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.dump +0 -0
  114. data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.text +13 -0
  115. data/spec/occi/parser/text_samples/occi_storage_rocci_server.dump +0 -0
  116. data/spec/occi/parser/text_samples/occi_storage_rocci_server.resource.dump +0 -0
  117. data/spec/occi/parser/text_samples/occi_storage_rocci_server.text +9 -0
  118. data/spec/occi/parser/text_spec.rb +274 -78
  119. data/spec/occi/parser/xml_samples/test.xml +352 -0
  120. data/spec/occi/parser_spec.rb +255 -104
  121. data/spec/occi-core_spec.rb +31 -0
  122. data/spec/spec_helper.rb +6 -2
  123. metadata +110 -111
  124. checksums.yaml +0 -7
  125. data/spec/occi/core/attribute_spec.rb +0 -0
@@ -4,94 +4,290 @@ module Occi
4
4
  module Parser
5
5
  describe Text do
6
6
 
7
- describe '.category' do
7
+ context '.category' do
8
8
 
9
- it 'parses a string with an OCCI Category to an OCCI Category' do
9
+ it 'parses a string describing an OCCI Category' do
10
10
  category_string = 'Category: a_a1-_;scheme="http://a.a/a#";class="kind";title="aA1!\"§$%&/()=?`´ß+*#-_.:,;<>";rel="http://a.a/b#a";location="/a1-A/";attributes="a_1-_.a1-_a a-1.a.b";actions="http://a.a/a1#a1 http://a.b1/b1#b2"'
11
11
 
12
12
  category = Occi::Parser::Text.category category_string
13
- category.term.should eq 'a_a1-_'
14
- category.scheme.should eq 'http://a.a/a#'
15
- category.class.should eq Occi::Core::Kind
16
- category.title.should eq 'aA1!\"§$%&/()=?`´ß+*#-_.:,;<>'
17
- category.related.first.should eq 'http://a.a/b#a'
18
- category.location.should eq '/a1-A/'
19
- category.attributes['a_1-_'].class.should eq Occi::Core::Attributes
20
- category.attributes['a_1-_']['a1-_a'].class.should eq Occi::Core::Properties
21
- category.attributes['a-1'].class.should eq Occi::Core::Attributes
22
- category.attributes['a-1']['a'].class.should eq Occi::Core::Attributes
23
- category.attributes['a-1']['a']['b'].class.should eq Occi::Core::Properties
24
- category.actions.to_a.any? {|action| action.to_s == 'http://a.a/a1#a1'}.should be_true
25
- category.actions.to_a.any? {|action| action.to_s == 'http://a.b1/b1#b2'}.should be_true
13
+ expected = Marshal.restore("\x04\bo:\x15Occi::Core::Kind\r:\f@schemeI\"\x12http://a.a/a#\x06:\x06ET:\n@termI\"\va_a1-_\x06;\aT:\v@titleI\"%aA1!\\\"\xC2\xA7$%&/()=?`\xC2\xB4\xC3\x9F+*#-_.:,;<>\x06;\aT:\x10@attributesC:\eOcci::Core::Attributes{\aI\"\na_1-_\x06;\aTC;\v{\x06I\"\na1-_a\x06;\aTo:\eOcci::Core::Properties\v:\r@default0:\n@typeI\"\vstring\x06;\aF:\x0E@requiredF:\r@mutableF:\r@patternI\"\a.*\x06;\aF:\x11@description0I\"\ba-1\x06;\aTC;\v{\x06I\"\x06a\x06;\aTC;\v{\x06I\"\x06b\x06;\aTo;\f\v;\r0;\x0EI\"\vstring\x06;\aF;\x0FF;\x10F;\x11I\"\a.*\x06;\aF;\x120:\f@parentI\"\x13http://a.a/b#a\x06;\aT:\r@actionso:\x18Occi::Core::Actions\x06:\n@hash{\ao:\x17Occi::Core::Action\t;\x06I\"\x13http://a.a/a1#\x06;\aT;\bI\"\aa1\x06;\aT;\t0;\nC;\v{\x00To;\x17\t;\x06I\"\x14http://a.b1/b1#\x06;\aT;\bI\"\ab2\x06;\aT;\t0;\nC;\v{\x00T:\x0E@entitieso:\x19Occi::Core::Entities\x06;\x16{\x00:\x0E@locationI\"\v/a1-A/\x06;\aT")
14
+
15
+ expect(category).to eql expected
16
+ end
17
+
18
+ it 'parses a string describing an OCCI Category with unquoted class value' do
19
+ category_string = 'Category: a_a1-_;scheme="http://a.a/a#";class=kind'
20
+ expected = Marshal.restore("\x04\bo:\x15Occi::Core::Kind\r:\f@schemeI\"\x12http://a.a/a#\x06:\x06ET:\n@termI\"\va_a1-_\x06;\aT:\v@title0:\x10@attributesC:\eOcci::Core::Attributes{\x00:\f@parent0:\r@actionso:\x18Occi::Core::Actions\x06:\n@hash{\x00:\x0E@entitieso:\x19Occi::Core::Entities\x06;\x0F{\x00:\x0E@locationI\"\r/a_a1-_/\x06;\aF")
21
+ category = Occi::Parser::Text.category category_string
22
+ expect(category).to eql expected
23
+ end
24
+
25
+ it 'parses a string describing an OCCI Category with uppercase term' do
26
+ category_string = 'Category: TERM;scheme="http://a.a/a#";class=kind'
27
+ expected = Marshal.restore("\x04\bo:\x15Occi::Core::Kind\r:\f@schemeI\"\x12http://a.a/a#\x06:\x06ET:\n@termI\"\tterm\x06;\aT:\v@title0:\x10@attributesC:\eOcci::Core::Attributes{\x00:\f@parent0:\r@actionso:\x18Occi::Core::Actions\x06:\n@hash{\x00:\x0E@entitieso:\x19Occi::Core::Entities\x06;\x0F{\x00:\x0E@locationI\"\v/term/\x06;\aF")
28
+ category = Occi::Parser::Text.category category_string
29
+ expect(category).to eql expected
30
+ end
31
+
32
+
33
+ it 'parses attributes correctly' do
34
+ resource_string = File.open("spec/occi/parser/text_samples/occi_resource_w_attributes.text", "rb").read
35
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_resource_w_attributes.dump", "rb"))
36
+ collection = Occi::Parser::Text.category resource_string
37
+ expect(collection).to eql expected
38
+ end
39
+
40
+ it 'parses inline links correctly' do
41
+ resource_string = File.open("spec/occi/parser/text_samples/occi_resource_w_inline_links_only.text", "rb").read
42
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_resource_w_inline_links_only.dump", "rb"))
43
+ collection = Occi::Parser::Text.category resource_string
44
+ expect(collection).to eql expected
45
+ end
46
+
47
+ it 'parses inline Links and Mixins correctly' do
48
+ resource_string = File.open("spec/occi/parser/text_samples/occi_resource_w_inline_links.text", "rb").read
49
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_resource_w_inline_links.dump", "rb"))
50
+ collection = Occi::Parser::Text.category resource_string
51
+ expect(collection).to eql expected
52
+ end
53
+
54
+ it 'parses action correctly' do
55
+ category_string = 'Category: restart;scheme="http://schemas.ogf.org/occi/infrastructure/compute/action#";class="action";title="Restart Compute instance";attributes="method"'
56
+ category = Occi::Parser::Text.category category_string
57
+ expected = Marshal.restore("\x04\bo:\x17Occi::Core::Action\t:\f@schemeI\"?http://schemas.ogf.org/occi/infrastructure/compute/action#\x06:\x06ET:\n@termI\"\frestart\x06;\aT:\v@titleI\"\x1DRestart Compute instance\x06;\aT:\x10@attributesC:\eOcci::Core::Attributes{\x06I\"\vmethod\x06;\aTo:\eOcci::Core::Properties\v:\r@default0:\n@typeI\"\vstring\x06;\aF:\x0E@requiredF:\r@mutableF:\r@patternI\"\a.*\x06;\aF:\x11@description0")
58
+
59
+ expect(category).to eql expected
60
+ end
61
+
62
+ it 'parses network resource from rOCCI server' do
63
+ resource_string = File.open("spec/occi/parser/text_samples/occi_network_rocci_server.text", "rb").read
64
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_network_rocci_server.dump", "rb"))
65
+ collection = Occi::Parser::Text.category resource_string
66
+ expect(collection).to eql expected
67
+ end
68
+
69
+ it 'parses storage resource from rOCCI server' do
70
+ resource_string = File.open("spec/occi/parser/text_samples/occi_storage_rocci_server.text", "rb").read
71
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_storage_rocci_server.dump", "rb"))
72
+ collection = Occi::Parser::Text.category resource_string
73
+ expect(collection).to eql expected
74
+ end
75
+
76
+ it 'parses compute resource from rOCCI server' do
77
+ resource_string = File.open("spec/occi/parser/text_samples/occi_compute_rocci_server.text", "rb").read
78
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_compute_rocci_server.dump", "rb"))
79
+ collection = Occi::Parser::Text.category resource_string
80
+ expect(collection).to eql expected
81
+ end
82
+
83
+ it 'parses model from rOCCI server' do
84
+ resource_string = File.open("spec/occi/parser/text_samples/occi_model_rocci_server.text", "rb").read
85
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_model_rocci_server.dump", "rb"))
86
+ collection = Occi::Parser::Text.category resource_string
87
+ expect(collection).to eql expected
88
+ end
89
+
90
+ it 'raises error for obviously nonsensical class' do
91
+ category_string = 'Category: restart;scheme="http://schemas.ogf.org/occi/infrastructure/compute/action#";class="actions";title="Restart Compute instance";attributes="method"'
92
+ expect{ category = Occi::Parser::Text.category category_string }.to raise_error(Occi::Errors::ParserInputError)
93
+ end
94
+
95
+ it 'raises error for cleverly nonsensical class' do
96
+ category_string = 'Category: restart;scheme="http://schemas.ogf.org/occi/infrastructure/compute/action#";class="action|mixin";title="Restart Compute instance";attributes="method"'
97
+ expect{ category = Occi::Parser::Text.category category_string }.to raise_error(Occi::Errors::ParserInputError)
98
+ end
99
+
100
+ it 'raises error for a nonsensical class even with lenient regexp' do
101
+ category_string = 'Category: restart;scheme="http://schemas.ogf.org/occi/infrastructure/compute/action#";class="invalid";title="Restart Compute instance";attributes="method"'
102
+
103
+ regexp_category = Occi::Parser::Text::Constants.const_get('REGEXP_CATEGORY')
104
+ regexp_category_alt = regexp_category
105
+ regexp_category_alt['action'] = 'invalid'
106
+
107
+ Occi::Parser::Text::Constants.const_set('REGEXP_CATEGORY', regexp_category_alt)
108
+
109
+ expect{ category = Occi::Parser::Text.category category_string }.to raise_error(Occi::Errors::ParserInputError)
110
+ Occi::Parser::Text.const_set('REGEXP_CATEGORY', regexp_category)
111
+ end
112
+ end
113
+ context '.resource' do
114
+ it 'parses network resource from rOCCI server' do
115
+ resource_string = File.open("spec/occi/parser/text_samples/occi_network_rocci_server.text", "rb").read
116
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_network_rocci_server.resource.dump", "rb"))
117
+ resource = Occi::Parser::Text.resource resource_string
118
+ expect(resource).to eql expected
119
+ end
120
+
121
+ it 'parses storage resource from rOCCI server' do
122
+ resource_string = File.open("spec/occi/parser/text_samples/occi_storage_rocci_server.text", "rb").read
123
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_storage_rocci_server.resource.dump", "rb"))
124
+ resource = Occi::Parser::Text.resource resource_string
125
+ expect(resource).to eql expected
126
+ end
127
+
128
+ it 'parses compute resource from rOCCI server' do
129
+ resource_string = File.open("spec/occi/parser/text_samples/occi_compute_rocci_server.text", "rb").read
130
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_compute_rocci_server.resource.dump", "rb"))
131
+ resource = Occi::Parser::Text.resource resource_string
132
+ expect(resource).to eql expected
133
+ end
134
+
135
+ it 'types parsed compute resource from rOCCI server as Occi::Infrastructure::Compute' do
136
+ resource_string = File.open("spec/occi/parser/text_samples/occi_compute_rocci_server.text", "rb").read
137
+ expected_class = Occi::Infrastructure::Compute
138
+ resource_class = Occi::Parser::Text.resource(resource_string).resources.first.class
139
+ expect(resource_class).to eql expected_class
140
+ end
141
+ end
142
+
143
+ context '.categories' do
144
+ it 'parses strings describing OCCI Categories' do
145
+ categories_string = File.open("spec/occi/parser/text_samples/occi_categories.text", "rb").read
146
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_categories.dump", "rb"))
147
+ categories = Occi::Parser::Text.categories categories_string
148
+ expect(categories).to eql expected
149
+ end
150
+
151
+ it 'parses strings describing OCCI Categories, skipping unparseable additions' do
152
+ categories_string = File.open("spec/occi/parser/text_samples/occi_categories.text", "rb").read
153
+ categories_string["\n"] = "\n\n&*$this won't parse\n"
154
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_categories.dump", "rb"))
155
+ categories = Occi::Parser::Text.categories categories_string
156
+ expect(categories).to eql expected
157
+ end
158
+
159
+ it 'does not fail on unparseable input' do
160
+ categories_string = "\n\n&*$this won't parse\n"
161
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_categories.dump", "rb"))
162
+ categories = Occi::Parser::Text.categories categories_string
163
+ expect(categories.blank?).to eql true
164
+ end
165
+
166
+ end
167
+
168
+ context '.link' do
169
+ it 'parses link resource instance' do
170
+ link_string = File.open("spec/occi/parser/text_samples/occi_link_resource_instance.text", "rb").read
171
+ link = Occi::Parser::Text.link link_string
172
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_link_resource_instance.dump", "rb"))
173
+ expected.links.each { |exp| exp.id = 'emptied' }
174
+ link.links.each { |lnk| lnk.id = 'emptied' }
175
+ expect(link).to eql expected
176
+ end
177
+
178
+ end
179
+
180
+ context '.location' do
181
+ it 'parses single location' do
182
+ location_string = "X-OCCI-Location: http://example.com:8090/a/b/vm1"
183
+ location = Occi::Parser::Text.location location_string
184
+ expected = "http://example.com:8090/a/b/vm1"
185
+ expect(location).to eql expected
186
+ end
187
+ end
188
+
189
+ context '.locations' do
190
+ let(:locations_string){ "X-OCCI-Location: http://example.com:8090/a/b/vm1\nX-OCCI-Location: http://example.com:8090/a/b/vm2" }
191
+ let(:expected){ ["http://example.com:8090/a/b/vm1", "http://example.com:8090/a/b/vm2"] }
192
+
193
+ it 'parses multiple locations' do
194
+ locations = Occi::Parser::Text.locations locations_string
195
+ expect(locations).to eql expected
26
196
  end
27
197
 
198
+ it 'parses multiple locations, skipping unparseable additions' do
199
+ locations_string["\n"] = "\n\n&*$this won't parse\n"
200
+ locations = Occi::Parser::Text.locations locations_string
201
+ expect(locations).to eql expected
202
+ end
203
+ end
204
+
205
+ context '.attribute' do
28
206
  end
29
207
 
30
- describe '.resource' do
31
-
32
- it 'parses a string with an OCCI Resource including attributes' do
33
- resource_string = %Q|Category: compute;scheme="http://schemas.ogf.org/occi/infrastructure#";class="kind"\nCategory: compute;scheme="http://opennebula.org/occi/infrastructure#";class="mixin"|
34
- resource_string << %Q|\nCategory: monitoring;scheme="https://occi.carach5.ics.muni.cz/occi/infrastructure/os_tpl#";class="mixin"|
35
- resource_string << %Q|\nCategory: small;scheme="https://occi.carach5.ics.muni.cz/occi/infrastructure/resource_tpl#";class="mixin"|
36
- resource_string << %Q|\nX-OCCI-Attribute: occi.core.id="ee13808d-7708-4341-a4ba-0e42e4818218"|
37
- resource_string << %Q|\nX-OCCI-Attribute: occi.core.title="TestVM"|
38
- resource_string << %Q|\nX-OCCI-Attribute: occi.compute.cores=1|
39
- resource_string << %Q|\nX-OCCI-Attribute: occi.compute.memory=1.7|
40
- resource_string << %Q|\nX-OCCI-Attribute: occi.compute.architecture="x86"|
41
- resource_string << %Q|\nX-OCCI-Attribute: occi.compute.speed=1|
42
- resource_string << %Q|\nX-OCCI-Attribute: occi.compute.state="active"|
43
- resource_string << %Q|\nX-OCCI-Attribute: org.opennebula.compute.cpu=1.0|
44
-
45
- collection = Occi::Parser::Text.resource resource_string.lines
46
- collection.resources.first.attributes['occi.compute.cores'].should eq(1)
47
- collection.resources.first.attributes['org.opennebula.compute.cpu'].should eq(1.0)
48
- collection.resources.first.attributes['occi.compute.architecture'].should eq("x86")
49
- collection.resources.first.attributes['occi.compute.memory'].should eq(1.7)
50
- end
51
-
52
- it 'parses a string with an OCCI Resource including inline OCCI Link definitions' do
53
- resource_string = %Q|Category: compute;scheme="http://schemas.ogf.org/occi/infrastructure#";class="kind"\nCategory: compute;scheme="http://opennebula.org/occi/infrastructure#";class="mixin"|
54
- resource_string << %Q|\nCategory: monitoring;scheme="https://occi.carach5.ics.muni.cz/occi/infrastructure/os_tpl#";class="mixin"|
55
- resource_string << %Q|\nCategory: small;scheme="https://occi.carach5.ics.muni.cz/occi/infrastructure/resource_tpl#";class="mixin"|
56
- resource_string << %Q|\nX-OCCI-Attribute: occi.core.id="ee13808d-7708-4341-a4ba-0e42e4818218"|
57
- resource_string << %Q|\nX-OCCI-Attribute: occi.core.title="TestVM"|
58
- resource_string << %Q|\nX-OCCI-Attribute: occi.compute.cores=1|
59
- resource_string << %Q|\nX-OCCI-Attribute: occi.compute.memory=1.7|
60
- resource_string << %Q|\nX-OCCI-Attribute: occi.compute.architecture="x86"|
61
- resource_string << %Q|\nX-OCCI-Attribute: occi.compute.speed=1|
62
- resource_string << %Q|\nX-OCCI-Attribute: occi.compute.state="active"|
63
- resource_string << %Q|\nX-OCCI-Attribute: org.opennebula.compute.cpu=1.0|
64
- resource_string << %Q|\nLink: </storage/e60aa2b8-0c86-5973-b93e-30c5c46d6eac>;rel="http://schemas.ogf.org/occi/infrastructure#storage";self="/storagelink/b2f7f1de-c60c-5b08-879c-81f52429c4ef";category="http://schemas.ogf.org/occi/infrastructure#storagelink";occi.core.id="b2f7f1de-c60c-5b08-879c-81f52429c4ef" occi.core.title="link to storage" occi.storagelink.deviceid="xvda" occi.storagelink.state="inactive" org.opennebula.storagelink.bus="ide" org.opennebula.storagelink.driver="tap2:tapdisk:aio:"|
65
- resource_string << %Q|\nLink: </network/e4bd81c4-adda-5626-840d-39bb7959db97>;rel="http://schemas.ogf.org/occi/infrastructure#network";self="/networkinterface/e75ab249-9325-511c-82b8-a7e4430381e3";category="http://schemas.ogf.org/occi/infrastructure#networkinterface";occi.core.id="e75ab249-9325-511c-82b8-a7e4430381e3" occi.core.title="link to network interface" occi.networkinterface.address="192.168.254.8" occi.networkinterface.mac="02:00:c0:a8:fe:08" occi.networkinterface.state="inactive" org.opennebula.networkinterface.bridge="xenbr0"|
66
-
67
- collection = Occi::Parser::Text.resource resource_string.lines
68
- collection.resources.should have(1).resource
69
- collection.links.should have(2).links
70
- end
71
-
72
- it 'parses a string with an OCCI Resource including inline OCCI Link definitions and OCCI Mixins' do
73
- resource_string = %Q|Category: compute; scheme="http://schemas.ogf.org/occi/infrastructure#"; class="kind"; title="Compute Resource"; rel="http://schemas.ogf.org/occi/core#resource"; location="https://egi-cloud.zam.kfa-juelich.de:8787/compute/"; attributes="occi.compute.architecture occi.compute.state{immutable} occi.compute.speed occi.compute.memory occi.compute.cores occi.compute.hostname"; actions="http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend"
74
- Category: os_vms; scheme="http://schemas.openstack.org/compute/instance#"; class="mixin"; location="https://egi-cloud.zam.kfa-juelich.de:8787/os_vms/"; attributes="org.openstack.compute.console.vnc{immutable} org.openstack.compute.state{immutable}"; actions="http://schemas.openstack.org/instance/action#chg_pwd http://schemas.openstack.org/instance/action#create_image"
75
- Link: </compute/04106bce-87eb-4f8f-a665-2f624e54ba46?action=stop>; rel="http://schemas.ogf.org/occi/infrastructure/compute/action#stop"
76
- Link: </compute/04106bce-87eb-4f8f-a665-2f624e54ba46?action=suspend>; rel="http://schemas.ogf.org/occi/infrastructure/compute/action#suspend"
77
- Link: </compute/04106bce-87eb-4f8f-a665-2f624e54ba46?action=restart>; rel="http://schemas.ogf.org/occi/infrastructure/compute/action#restart"
78
- Link: </network/public>; rel="http://schemas.ogf.org/occi/infrastructure#network"; self="/network/interface/6a7a9446-a146-4faf-a961-52f66d2808df"; category="http://schemas.ogf.org/occi/infrastructure#networkinterface http://schemas.ogf.org/occi/infrastructure/networkinterface#ipnetworkinterface"; occi.networkinterface.gateway="0.0.0.0"; occi.networkinterface.mac="aa:bb:cc:dd:ee:ff"; occi.networkinterface.interface="eth0"; occi.networkinterface.state="active"; occi.networkinterface.allocation="static"; occi.networkinterface.address="134.94.32.154"; occi.core.source="/compute/04106bce-87eb-4f8f-a665-2f624e54ba46"; occi.core.target="/network/public"; occi.core.id="/network/interface/6a7a9446-a146-4faf-a961-52f66d2808df"
79
- Link: </network/admin>; rel="http://schemas.ogf.org/occi/infrastructure#network"; self="/network/interface/02b630f6-087e-4969-b04c-1e22d9480dec"; category="http://schemas.ogf.org/occi/infrastructure#networkinterface http://schemas.ogf.org/occi/infrastructure/networkinterface#ipnetworkinterface"; occi.networkinterface.gateway="192.168.16.1"; occi.networkinterface.mac="fa:16:3e:45:1c:26"; occi.networkinterface.interface="eth0"; occi.networkinterface.state="active"; occi.networkinterface.allocation="static"; occi.networkinterface.address="192.168.16.103"; occi.core.source="/compute/04106bce-87eb-4f8f-a665-2f624e54ba46"; occi.core.target="/network/admin"; occi.core.id="/network/interface/02b630f6-087e-4969-b04c-1e22d9480dec"
80
- X-OCCI-Attribute: org.openstack.compute.console.vnc="http://134.94.32.4:6080/vnc_auto.html?token=9923dc1b-eca0-4c62-81a8-a0dd6848341a"
81
- X-OCCI-Attribute: occi.compute.architecture="x86"
82
- X-OCCI-Attribute: occi.compute.state="active"
83
- X-OCCI-Attribute: occi.compute.speed="0.0"
84
- X-OCCI-Attribute: occi.compute.cores="1"
85
- X-OCCI-Attribute: occi.compute.memory="1.0"
86
- X-OCCI-Attribute: org.openstack.compute.state="active"
87
- X-OCCI-Attribute: occi.compute.hostname="openmodeller-test-bjoernh"
88
- X-OCCI-Attribute: occi.core.id="04106bce-87eb-4f8f-a665-2f624e54ba46"|
89
-
90
- collection = Occi::Parser::Text.resource resource_string.lines
91
- collection.resources.should have(1).resource
92
- collection.links.should have(5).links
208
+ context '.link_string' do
209
+ it 'parses string with category set' do
210
+ link_string = File.open("spec/occi/parser/text_samples/occi_link_simple.text", "rb").read
211
+ link = Occi::Parser::Text.link_string link_string, nil
212
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_link_simple.link_string.dump", "rb"))
213
+ expect(link).to eql expected
214
+ end
215
+
216
+ it 'parses link with category' do
217
+ link_string = File.open("spec/occi/parser/text_samples/occi_link_w_category.text", "rb").read
218
+ link = Occi::Parser::Text.link_string link_string, nil
219
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_link_w_category.dump", "rb"))
220
+ expect(link).to eql expected
93
221
  end
94
222
 
223
+ it 'parses link with attributes' do
224
+ link_string = File.open("spec/occi/parser/text_samples/occi_link_w_attributes.text", "rb").read
225
+ link = Occi::Parser::Text.link_string link_string, nil
226
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_link_w_attributes.dump", "rb"))
227
+ expect(link).to eql expected
228
+ end
229
+
230
+ it 'parses string with category unset' do
231
+ link_string = 'Link: </compute/04106bce-87eb-4f8f-a665-2f624e54ba46?action=restart>; rel="http://schemas.ogf.org/occi/infrastructure/compute/action#restart"'
232
+ link = Occi::Parser::Text.link_string(link_string, "source")
233
+ expected = Marshal.restore("\x04\bo:\x15Occi::Core::Link\x0E:\n@kindo:\x15Occi::Core::Kind\r:\f@schemeI\"&http://schemas.ogf.org/occi/core#\x06:\x06EF:\n@termI\"\tlink\x06;\tF:\v@titleI\"\tlink\x06;\tF:\x10@attributesC:\eOcci::Core::Attributes{\x06I\"\tocci\x06;\tFC;\r{\x06I\"\tcore\x06;\tFC;\r{\rI\"\aid\x06;\tFo:\eOcci::Core::Properties\v:\r@default0:\n@typeI\"\vstring\x06;\tF:\x0E@requiredF:\r@mutableF:\r@patternI\"A[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\x06;\tF:\x11@description0I\"\b_id\x06;\tFo;\x0E\v;\x0F0;\x10@\x11;\x11F;\x12F;\x13@\x12;\x140I\"\ntitle\x06;\tFo;\x0E\v;\x0F0;\x10I\"\vstring\x06;\tF;\x11F;\x12T;\x13I\"\a.*\x06;\tF;\x140I\"\v_title\x06;\tFo;\x0E\v;\x0F0;\x10@\x17;\x11F;\x12T;\x13@\x18;\x140I\"\vtarget\x06;\tFo;\x0E\v;\x0F0;\x10I\"\vstring\x06;\tF;\x11F;\x12T;\x13I\"\a.*\x06;\tF;\x140I\"\f_target\x06;\tFo;\x0E\v;\x0F0;\x10@\x1D;\x11F;\x12T;\x13@\x1E;\x140I\"\vsource\x06;\tFo;\x0E\v;\x0F0;\x10I\"\vstring\x06;\tF;\x11F;\x12T;\x13I\"\a.*\x06;\tF;\x140I\"\f_source\x06;\tFo;\x0E\v;\x0F0;\x10@#;\x11F;\x12T;\x13@$;\x140:\f@parento;\a\r;\bI\"&http://schemas.ogf.org/occi/core#\x06;\tF;\nI\"\ventity\x06;\tF;\vI\"\ventity\x06;\tF;\fC;\r{\x06@\vC;\r{\x06@\rC;\r{\t@\x0F@\x10@\x13@\x14@\x15@\x16@\x19@\x1A;\x150:\r@actionso:\x18Occi::Core::Actions\x06:\n@hash{\x00:\x0E@entitieso:\x19Occi::Core::Entities\x06;\x18{\x00:\x0E@locationI\"\r/entity/\x06;\tF;\x16o;\x17\x06;\x18{\x00;\x19o;\x1A\x06;\x18{\x00;\eI\"\v/link/\x06;\tF:\f@mixinso:\x17Occi::Core::Mixins\a;\x18{\x00:\f@entity@\x00;\fIC;\r{\x06@\vIC;\r{\x06@\rIC;\r{\r@\x0F0@\x13@\x14@\x150@\x19@\x1A@\e0@\x1F@ @!0@%@&\x06:\x0F@convertedT\x06;\x1FT\x06;\x1FT;\x16o;\x17\x06;\x18{\x00;\e0:\t@relo;\a\r;\bI\"?http://schemas.ogf.org/occi/infrastructure/compute/action#\x06;\tT;\nI\"\frestart\x06;\tT;\v0;\fC;\r{\x00;\x15@';\x16o;\x17\x06;\x18{\x00;\x19o;\x1A\x06;\x18{\x00;\eI\"\x0E/restart/\x06;\tF:\f@sourceI\"\vsource\x06;\tT:\f@targetI\"A/compute/04106bce-87eb-4f8f-a665-2f624e54ba46?action=restart\x06;\tT:\b@id0")
234
+ expected.id = 'epmtied'
235
+ link.id = 'epmtied'
236
+ expect(link).to eql expected
237
+ end
238
+ end
239
+
240
+ context 'compatibility' do
241
+ after(:each) { Occi::Settings.reload! }
242
+ context 'terms' do
243
+ it 'parses uppercase term, compatibility on' do
244
+ Occi::Settings['compatibility']=true
245
+ category_string = 'Category: TERM;scheme="http://a.a/a#";class=kind'
246
+ expected = Marshal.restore("\x04\bo:\x15Occi::Core::Kind\r:\f@schemeI\"\x12http://a.a/a#\x06:\x06ET:\n@termI\"\tterm\x06;\aT:\v@title0:\x10@attributesC:\eOcci::Core::Attributes{\x00:\f@parent0:\r@actionso:\x18Occi::Core::Actions\x06:\n@hash{\x00:\x0E@entitieso:\x19Occi::Core::Entities\x06;\x0F{\x00:\x0E@locationI\"\v/term/\x06;\aF")
247
+ category = Occi::Parser::Text.category category_string
248
+ expect(category).to eql expected
249
+ end
250
+
251
+ it 'refuses uppercase term, compatibility off' do
252
+ Occi::Settings['compatibility']=false
253
+ category_string = 'Category: TERM;scheme="http://a.a/a#";class=kind'
254
+ expect{ category = Occi::Parser::Text.category category_string }.to raise_error(Occi::Errors::ParserInputError)
255
+ end
256
+
257
+ it 'parses term starting with number, compatibility on' do
258
+ Occi::Settings['compatibility']=true
259
+ category_string = 'Category: 1TERM;scheme="http://a.a/a#";class=kind'
260
+ expected = Marshal.restore("\x04\bo:\x15Occi::Core::Kind\r:\f@schemeI\"\x12http://a.a/a#\x06:\x06ET:\n@termI\"\n1term\x06;\aT:\v@title0:\x10@attributesC:\eOcci::Core::Attributes{\x00:\f@parent0:\r@actionso:\x18Occi::Core::Actions\x06:\n@hash{\x00:\x0E@entitieso:\x19Occi::Core::Entities\x06;\x0F{\x00:\x0E@locationI\"\f/1term/\x06;\aF")
261
+ category = Occi::Parser::Text.category category_string
262
+ expect(category).to eql expected
263
+ end
264
+
265
+ it 'refuses term starting with number, compatibility off' do
266
+ Occi::Settings['compatibility']=false
267
+ category_string = 'Category: 1TERM;scheme="http://a.a/a#";class=kind'
268
+ expect{ category = Occi::Parser::Text.category category_string }.to raise_error(Occi::Errors::ParserInputError)
269
+ end
270
+
271
+ end
272
+ context 'schemes' do
273
+ it 'parses a Category, compatibility on' do
274
+ Occi::Settings['compatibility']=true
275
+ category_string = 'Category: a_a1-_;scheme="http://a.a/a#a_a1-_";class="kind";title="aA1!\"§$%&/()=?`´ß+*#-_.:,;<>";rel="http://a.a/b#a";location="/a1-A/";attributes="a_1-_.a1-_a a-1.a.b";actions="http://a.a/a1#a1 http://a.b1/b1#b2"'
276
+ category = Occi::Parser::Text.category category_string
277
+ expected = Marshal.restore("\x04\bo:\x15Occi::Core::Kind\r:\f@schemeI\"\x12http://a.a/a#\x06:\x06ET:\n@termI\"\va_a1-_\x06;\aT:\v@titleI\"%aA1!\\\"\xC2\xA7$%&/()=?`\xC2\xB4\xC3\x9F+*#-_.:,;<>\x06;\aT:\x10@attributesC:\eOcci::Core::Attributes{\aI\"\na_1-_\x06;\aTC;\v{\x06I\"\na1-_a\x06;\aTo:\eOcci::Core::Properties\v:\r@default0:\n@typeI\"\vstring\x06;\aF:\x0E@requiredF:\r@mutableF:\r@patternI\"\a.*\x06;\aF:\x11@description0I\"\ba-1\x06;\aTC;\v{\x06I\"\x06a\x06;\aTC;\v{\x06I\"\x06b\x06;\aTo;\f\v;\r0;\x0EI\"\vstring\x06;\aF;\x0FF;\x10F;\x11I\"\a.*\x06;\aF;\x120:\f@parentI\"\x13http://a.a/b#a\x06;\aT:\r@actionso:\x18Occi::Core::Actions\x06:\n@hash{\ao:\x17Occi::Core::Action\t;\x06I\"\x13http://a.a/a1#\x06;\aT;\bI\"\aa1\x06;\aT;\t0;\nC;\v{\x00To;\x17\t;\x06I\"\x14http://a.b1/b1#\x06;\aT;\bI\"\ab2\x06;\aT;\t0;\nC;\v{\x00T:\x0E@entitieso:\x19Occi::Core::Entities\x06;\x16{\x00:\x0E@locationI\"\v/a1-A/\x06;\aT")
278
+ expect(category).to eql expected
279
+ end
280
+
281
+ it 'parses a Category, compatibility off' do
282
+ Occi::Settings['compatibility']=false
283
+ category_string = 'Category: a_a1-_;scheme="http://a.a/a#a_a1-_";class="kind";title="aA1!\"§$%&/()=?`´ß+*#-_.:,;<>";rel="http://a.a/b#a";location="/a1-A/";attributes="a_1-_.a1-_a a-1.a.b";actions="http://a.a/a1#a1 http://a.b1/b1#b2"'
284
+ expect{ category = Occi::Parser::Text.category category_string }.to raise_error(Occi::Errors::ParserInputError)
285
+ end
286
+ end
287
+ end
288
+
289
+ context 'other OCCI implementations' do
290
+ it 'renders correctly OCCI from other sources'
95
291
  end
96
292
 
97
293
  end