Skip to content
This repository

openstack modifications #2462

Merged
merged 1 commit into from 4 months ago

5 participants

Eugene Howe Coveralls Wesley Beary Kyle Rames Thom Mahoney
Eugene Howe
  • add model and collection for security group rules
  • add mock data for networks
  • returns address in create_server mock
  • proper security group rule mocks
  • proper security group mocks
Coveralls

Coverage Status

Coverage remained the same when pulling 91690b3 on engineyard:openstack into 216cf26 on fog:master.

Coveralls

Coverage Status

Coverage remained the same when pulling 91690b3 on engineyard:openstack into 216cf26 on fog:master.

Wesley Beary
Owner

@krames - could you review? Thanks!

lib/fog/openstack/models/compute/security_group_rules.rb
... ...
@@ -0,0 +1,21 @@
  1
+require 'fog/core/collection'
  2
+require 'fog/openstack/models/compute/security_group_rule'
  3
+
  4
+module Fog
  5
+  module Compute
  6
+    class OpenStack
  7
+      class SecurityGroupRules < Fog::Collection
  8
+
  9
+        model Fog::Compute::OpenStack::SecurityGroupRule
  10
+
  11
+        def get(security_group_rule_id)
  12
+          if security_group_rule_id
  13
+            new(service.get_security_group_rule(security_group_rule_id).body['security_group_rule'])
2
Kyle Rames Collaborator
krames added a note

Can we break this into two lines? It should make it easier to find issues if we ever get a stack trace.

Changing it to this:

  body = service.get_security_group_rule(security_group_rule_id).body
  new(body['security_group_rule'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/fog/openstack/models/compute/security_group.rb
... ...
@@ -13,6 +13,9 @@ class SecurityGroup < Fog::Model
13 13
         attribute :rules
14 14
         attribute :tenant_id
15 15
 
  16
+        def security_group_rules
  17
+          Fog::Compute::OpenStack::SecurityGroupRules.load(rules)
2
Kyle Rames Collaborator
krames added a note

Would users ever use the rules attribute directly? If not, what do you think about adding deprecation warnings if users try to access this attribute and changing this line to

Fog::Compute::OpenStack::SecurityGroupRules.load(attributes[:rules])

Will do. Have a look at the next commit (I'll comment when I make the commit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Kyle Rames
Collaborator

@ehowe Thanks for the PR!

Overall it looks great, but I did have a couple comments. In addition to those, can I get you to write tests for get_security_group_rule request and the model security_group_rule and collection for security_group_rules?

Here are a couple examples to get you started:

request test => https://github.com/fog/fog/blob/master/tests/rackspace/requests/compute_v2/keypair_tests.rb
model test => https://github.com/fog/fog/blob/master/tests/rackspace/models/monitoring/agent_token_tests.rb
collection test => https://github.com/fog/fog/blob/master/tests/rackspace/models/monitoring/agent_tokens_tests.rb

Let me know if you need any help getting started with our testing framework shindo.

Thom Mahoney openstack modifications
* add model and collection for security group rules
* add mock data for networks
* returns address in create_server mock
* proper security group rule mocks
* proper security group mocks
0192e53
Coveralls

Coverage Status

Coverage increased (+0.59%) when pulling 0192e53 on engineyard:openstack into 8d1062b on fog:master.

Thom Mahoney

@krames what do you think?

Kyle Rames
Collaborator

@thommahoney LGTM! :shipit:

Thanks again for the PR!

Kyle Rames krames merged commit 5346176 into from
Kyle Rames krames closed this
Wesley Beary
Owner
Thom Mahoney

@burns you are correct. We're using string keys for the security group mock data now. So that seed data does need to change.

@burns master seems to be green. Let me know if you want me to look into a specific failure. https://travis-ci.org/fog/fog/builds/15552477

Owner

Yeah, any insight would be awesome (I was just trying to look in to it and nothing was jumping out at me as obvious in terms of why it would sometimes be failing on us).

Owner

Just did a bit of work around it here: b056df5

Not sure it will fix it (since I'm not sure why it was breaking), but it at least streamlines and removes some of the failure vectors.

Owner

Looks like it might be fixed, fwiw. Now a different error is breaking the build anyway. Will continue to monitor.

Nat Welch icco referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 2 authors.

Dec 09, 2013
Thom Mahoney openstack modifications
* add model and collection for security group rules
* add mock data for networks
* returns address in create_server mock
* proper security group rule mocks
* proper security group mocks
0192e53
This page is out of date. Refresh to see the latest.
3  lib/fog/openstack/compute.rb
@@ -28,6 +28,8 @@ class OpenStack < Fog::Service
28 28
       collection  :addresses
29 29
       model       :security_group
30 30
       collection  :security_groups
  31
+      model       :security_group_rule
  32
+      collection  :security_group_rules
31 33
       model       :key_pair
32 34
       collection  :key_pairs
33 35
       model       :tenant
@@ -128,6 +130,7 @@ class OpenStack < Fog::Service
128 130
       request :create_security_group_rule
129 131
       request :delete_security_group
130 132
       request :delete_security_group_rule
  133
+      request :get_security_group_rule
131 134
 
132 135
       # Key Pair
133 136
       request :list_key_pairs
1  lib/fog/openstack/models/compute/host.rb
@@ -10,6 +10,7 @@ class Host < Fog::Model
10 10
         attribute :host_name
11 11
         attribute :service_name
12 12
         attribute :details
  13
+        attribute :zone
13 14
 
14 15
         def initialize(attributes)
15 16
           attributes["service_name"] = attributes.delete "service"
22  lib/fog/openstack/models/compute/security_group.rb
@@ -3,16 +3,30 @@
3 3
 module Fog
4 4
   module Compute
5 5
     class OpenStack
6  
-
7 6
       class SecurityGroup < Fog::Model
8 7
 
9 8
         identity  :id
10 9
 
11 10
         attribute :name
12 11
         attribute :description
13  
-        attribute :rules
  12
+        attribute :security_group_rules, :aliases => "rules"
14 13
         attribute :tenant_id
15 14
 
  15
+        def security_group_rules
  16
+          Fog::Compute::OpenStack::SecurityGroupRules.new(:service => service).load(attributes[:security_group_rules])
  17
+        end
  18
+
  19
+        def rules
  20
+          Fog::Logger.deprecation('#rules is deprecated. Use #security_group_rules instead')
  21
+          attributes[:security_group_rules]
  22
+        end
  23
+
  24
+        # no one should be calling this because it doesn't do anything
  25
+        # useful but we deprecated the rules attribute and need to maintain the API
  26
+        def rules=(new_rules)
  27
+          Fog::Logger.deprecation('#rules= is deprecated. Use the Fog::Compute::Openstack::SecurityGroupRules collection to create new rules.')
  28
+          attributes[:security_group_rules] = new_rules
  29
+        end
16 30
 
17 31
         def save
18 32
           requires :name, :description
@@ -21,7 +35,6 @@ def save
21 35
           true
22 36
         end
23 37
 
24  
-
25 38
         def destroy
26 39
           requires :id
27 40
           service.delete_security_group(id)
@@ -29,15 +42,16 @@ def destroy
29 42
         end
30 43
 
31 44
         def create_security_group_rule(min, max, ip_protocol = "tcp", cidr = "0.0.0.0/0", group_id = nil)
  45
+          Fog::Logger.deprecation('#create_security_group_rule is deprecated. Use the Fog::Compute::Openstack::SecurityGroupRules collection to create new rules.')
32 46
           requires :id
33 47
           service.create_security_group_rule(id, ip_protocol, min, max, cidr, group_id)
34 48
         end
35 49
 
36 50
         def delete_security_group_rule(rule_id)
  51
+          Fog::Logger.deprecation('#create_security_group_rule is deprecated. Use the Fog::Compute::Openstack::SecurityGroupRule objects to destroy rules.')
37 52
           service.delete_security_group_rule(rule_id)
38 53
           true
39 54
         end
40  
-
41 55
       end
42 56
     end
43 57
   end
32  lib/fog/openstack/models/compute/security_group_rule.rb
... ...
@@ -0,0 +1,32 @@
  1
+require 'fog/core/model'
  2
+
  3
+module Fog
  4
+  module Compute
  5
+    class OpenStack
  6
+      class SecurityGroupRule < Fog::Model
  7
+        identity :id
  8
+
  9
+        attribute :from_port
  10
+        attribute :group
  11
+        attribute :ip_protocol
  12
+        attribute :to_port
  13
+        attribute :parent_group_id
  14
+        attribute :ip_range
  15
+
  16
+        def save
  17
+          requires :ip_protocol, :from_port, :to_port, :parent_group_id
  18
+          cidr = ip_range && ip_range["cidr"]
  19
+          if rule = service.create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group).data[:body]
  20
+            merge_attributes(rule["security_group_rule"])
  21
+          end
  22
+        end
  23
+
  24
+        def destroy
  25
+          requires :id
  26
+          service.delete_security_group_rule(id)
  27
+          true
  28
+        end
  29
+      end
  30
+    end
  31
+  end
  32
+end
22  lib/fog/openstack/models/compute/security_group_rules.rb
... ...
@@ -0,0 +1,22 @@
  1
+require 'fog/core/collection'
  2
+require 'fog/openstack/models/compute/security_group_rule'
  3
+
  4
+module Fog
  5
+  module Compute
  6
+    class OpenStack
  7
+      class SecurityGroupRules < Fog::Collection
  8
+
  9
+        model Fog::Compute::OpenStack::SecurityGroupRule
  10
+
  11
+        def get(security_group_rule_id)
  12
+          if security_group_rule_id
  13
+            body = service.get_security_group_rule(security_group_rule_id).body
  14
+            new(body['security_group_rule'])
  15
+          end
  16
+        rescue Fog::Compute::OpenStack::NotFound
  17
+          nil
  18
+        end
  19
+      end
  20
+    end
  21
+  end
  22
+end
36  lib/fog/openstack/network.rb
@@ -118,10 +118,40 @@ class OpenStack < Fog::Service
118 118
       class Mock
119 119
         def self.data
120 120
           @data ||= Hash.new do |hash, key|
  121
+            network_id = Fog::UUID.uuid
  122
+            subnet_id  = Fog::UUID.uuid
  123
+            tenant_id  = Fog::Mock.random_hex(8)
  124
+
121 125
             hash[key] = {
122  
-              :networks => {},
  126
+              :networks => {
  127
+                network_id => {
  128
+                  'id'                    => network_id,
  129
+                  'name'                  => 'Public',
  130
+                  'subnets'               => [subnet_id],
  131
+                  'shared'                => true,
  132
+                  'status'                => 'ACTIVE',
  133
+                  'tenant_id'             => tenant_id,
  134
+                  'provider_network_type' => 'vlan',
  135
+                  'router:external'       => false,
  136
+                  'admin_state_up'        => true,
  137
+                }
  138
+              },
123 139
               :ports => {},
124  
-              :subnets => {},
  140
+              :subnets => {
  141
+                subnet_id => {
  142
+                  'id'               => subnet_id,
  143
+                  'name'             => "Public",
  144
+                  'network_id'       => network_id,
  145
+                  'cidr'             => "192.168.0.0/22",
  146
+                  'ip_version'       => 4,
  147
+                  'gateway_ip'       => Fog::Mock.random_ip,
  148
+                  'allocation_pools' => [],
  149
+                  'dns_nameservers'  => [Fog::Mock.random_ip, Fog::Mock.random_ip],
  150
+                  'host_routes'      => [Fog::Mock.random_ip],
  151
+                  'enable_dhcp'      => true,
  152
+                  'tenant_id'        => tenant_id,
  153
+                }
  154
+              },
125 155
               :floating_ips => {},
126 156
               :routers => {},
127 157
               :lb_pools => {},
@@ -140,7 +170,7 @@ def self.data
140 170
                   "subnet" => 10,
141 171
                   "network" => 10,
142 172
                   "floatingip" => 50,
143  
-                  "tenant_id" => Fog::Mock.random_hex(8),
  173
+                  "tenant_id" => tenant_id,
144 174
                   "router" => 10,
145 175
                   "port" => 30
146 176
                 }
6  lib/fog/openstack/requests/compute/create_security_group.rb
@@ -23,10 +23,10 @@ def create_security_group(name, description)
23 23
 
24 24
       class Mock
25 25
         def create_security_group(name, description)
26  
-          Fog::Identity.new(:provider => 'OpenStack')
  26
+          Fog::Identity::OpenStack.new(:openstack_auth_url => credentials[:openstack_auth_url])
27 27
           tenant_id = Fog::Identity::OpenStack::Mock.data[current_tenant][:tenants].keys.first
28 28
           security_group_id = Fog::Mock.random_numbers(2).to_i
29  
-          self.data[:security_groups][security_group_id] = {
  29
+          self.data[:security_groups][security_group_id.to_s] = {
30 30
             'tenant_id' => tenant_id,
31 31
             'rules'     => [],
32 32
             'id'        => security_group_id,
@@ -42,7 +42,7 @@ def create_security_group(name, description)
42 42
             'Content-Length' => Fog::Mock.random_numbers(3).to_s,
43 43
             'Date'           => Date.new}
44 44
           response.body = {
45  
-            'security_group' => self.data[:security_groups][security_group_id]
  45
+            'security_group' => self.data[:security_groups][security_group_id.to_s]
46 46
           }
47 47
           response
48 48
         end
2  lib/fog/openstack/requests/compute/create_security_group_rule.rb
@@ -47,7 +47,7 @@ def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port,
47 47
               'cidr'   => cidr
48 48
             }
49 49
           }
50  
-          self.data[:security_groups][parent_group_id]['rules'].push(rule)
  50
+          self.data[:security_groups][parent_group_id.to_s]['rules'].push(rule)
51 51
           response.body = {
52 52
             'security_group_rule' => rule
53 53
           }
17  lib/fog/openstack/requests/compute/create_server.rb
@@ -13,7 +13,7 @@ def create_server(name, image_ref, flavor_ref, options = {})
13 13
           }
14 14
 
15 15
           vanilla_options = ['metadata', 'accessIPv4', 'accessIPv6',
16  
-                             'availability_zone', 'user_data', 'key_name', 
  16
+                             'availability_zone', 'user_data', 'key_name',
17 17
                              'adminPass', 'config_drive', 'min_count', 'max_count',
18 18
                              'return_reservation_id'
19 19
                             ]
@@ -107,7 +107,6 @@ def create_server(name, image_ref, flavor_ref, options = {})
107 107
                        response.body["user"]["id"]
108 108
                     end
109 109
 
110  
-
111 110
           mock_data = {
112 111
             'addresses'    => {},
113 112
             'flavor'       => {"id" => flavor_ref, "links"=>[{"href"=>"http://nova1:8774/admin/flavors/1", "rel"=>"bookmark"}]},
@@ -127,10 +126,18 @@ def create_server(name, image_ref, flavor_ref, options = {})
127 126
             'config_drive' => options['config_drive'] || '',
128 127
           }
129 128
 
  129
+          if nics = options['nics']
  130
+            nics.each do |nic|
  131
+              mock_data["addresses"].merge!(
  132
+                "Public" => [{ 'addr' => Fog::Mock.random_ip }]
  133
+              )
  134
+            end
  135
+          end
  136
+
130 137
           response_data = {}
131 138
           if options['return_reservation_id'] == 'True' then
132 139
             response_data = { 'reservation_id' => "r-#{Fog::Mock.random_numbers(6).to_s}" }
133  
-          else   
  140
+          else
134 141
             response_data = {
135 142
               'adminPass'       => 'password',
136 143
               'id'              => server_id,
@@ -156,12 +163,12 @@ def create_server(name, image_ref, flavor_ref, options = {})
156 163
           self.data[:last_modified][:servers][server_id] = Time.now
157 164
           self.data[:servers][server_id] = mock_data
158 165
           if options['return_reservation_id'] == 'True' then
159  
-            response.body = response_data 
  166
+            response.body = response_data
160 167
           else
161 168
             response.body = { 'server' => response_data }
162 169
           end
163 170
           response
164  
-        end      
  171
+        end
165 172
       end
166 173
     end
167 174
   end
2  lib/fog/openstack/requests/compute/delete_security_group.rb
@@ -15,7 +15,7 @@ def delete_security_group(security_group_id)
15 15
 
16 16
       class Mock
17 17
         def delete_security_group(security_group_id)
18  
-          self.data[:security_groups].delete security_group_id
  18
+          self.data[:security_groups].delete security_group_id.to_s
19 19
 
20 20
           response = Excon::Response.new
21 21
           response.status = 202
2  lib/fog/openstack/requests/compute/delete_security_group_rule.rb
@@ -15,6 +15,8 @@ def delete_security_group_rule(security_group_rule_id)
15 15
 
16 16
       class Mock
17 17
         def delete_security_group_rule(security_group_rule_id)
  18
+          security_group = self.data[:security_groups].values.detect{|sg| sg["rules"].detect{ |sgr| sgr["id"].to_s == security_group_rule_id.to_s }}
  19
+          security_group["rules"].reject! { |sgr| sgr["id"] == security_group_rule_id }
18 20
           response = Excon::Response.new
19 21
           response.status = 202
20 22
           response.headers = {
38  lib/fog/openstack/requests/compute/get_security_group.rb
@@ -15,32 +15,22 @@ def get_security_group(security_group_id)
15 15
 
16 16
       class Mock
17 17
         def get_security_group(security_group_id)
  18
+          security_group = self.data[:security_groups][security_group_id.to_s]
18 19
           response = Excon::Response.new
19  
-          response.status = 200
20  
-          response.headers = {
21  
-            "X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3",
22  
-            "Content-Type" => "application/json",
23  
-            "Content-Length" => "167",
24  
-            "Date" => Date.new
25  
-          }
26  
-          response.body = {
27  
-            "security_group" => {
28  
-              "rules" => [{
29  
-                "from_port" => 44,
30  
-                "group" => {},
31  
-                "ip_protocol" => "tcp",
32  
-                "to_port" => 55,
33  
-                "parent_group_id" => 1,
34  
-                "ip_range" => {
35  
-                  "cidr" => "10.10.10.10/24"
36  
-                }, "id"=>1
37  
-              }],
38  
-              "tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2",
39  
-              "id"=>security_group_id,
40  
-              "name"=>"default",
41  
-              "description"=>"default"
  20
+          if security_group
  21
+            response.status = 200
  22
+            response.headers = {
  23
+              "X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3",
  24
+              "Content-Type" => "application/json",
  25
+              "Content-Length" => "167",
  26
+              "Date" => Date.new
42 27
             }
43  
-          }
  28
+            response.body = {
  29
+              "security_group" => security_group
  30
+            }
  31
+          else
  32
+            raise Fog::Compute::OpenStack::NotFound, "Security group #{security_group_id} does not exist"
  33
+          end
44 34
           response
45 35
         end
46 36
       end # mock
38  lib/fog/openstack/requests/compute/get_security_group_rule.rb
... ...
@@ -0,0 +1,38 @@
  1
+module Fog
  2
+  module Compute
  3
+    class OpenStack
  4
+      class Real
  5
+        def get_security_group_rule(security_group_rule_id)
  6
+          request(
  7
+            :expects  => [200],
  8
+            :method   => 'GET',
  9
+            :path     => "os-security-group-rules/#{security_group_rule_id}"
  10
+          )
  11
+        end
  12
+      end
  13
+
  14
+      class Mock
  15
+        def get_security_group_rule(security_group_rule_id)
  16
+          security_group_rule = nil
  17
+          self.data[:security_groups].detect{|id, sg| security_group_rule = sg["rules"].detect{ |sgr| sgr["id"].to_s == security_group_rule_id.to_s }}
  18
+          response = Excon::Response.new
  19
+          if security_group_rule
  20
+            response.status = 200
  21
+            response.headers = {
  22
+              "X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3",
  23
+              "Content-Type" => "application/json",
  24
+              "Content-Length" => "167",
  25
+              "Date" => Date.new
  26
+            }
  27
+            response.body = {
  28
+              "security_group_rule" => security_group_rule
  29
+            }
  30
+          else
  31
+            raise Fog::Compute::OpenStack::NotFound, "Security group rule #{security_group_rule_id} does not exist"
  32
+          end
  33
+          response
  34
+        end
  35
+      end # mock
  36
+    end # openstack
  37
+  end #compute
  38
+end #fog
6  lib/fog/openstack/requests/compute/list_hosts.rb
@@ -14,12 +14,12 @@ def list_hosts
14 14
       end
15 15
 
16 16
       class Mock
17  
-        
  17
+
18 18
         def list_hosts
19 19
           response = Excon::Response.new
20 20
           response.status = 200
21 21
           response.body = { "hosts" => [
22  
-              {"host_name" => "host.test.net", "service"=>"compute"}
  22
+              {"host_name" => "host.test.net", "service"=>"compute", "zone" => "az1"}
23 23
             ]
24 24
           }
25 25
           response
@@ -29,4 +29,4 @@ def list_hosts
29 29
       end # mock
30 30
     end # openstack
31 31
   end # compute
32  
-end # fog
  32
+end # fog
4  lib/fog/openstack/volume.rb
@@ -9,7 +9,7 @@ class OpenStack < Fog::Service
9 9
                  :openstack_service_type, :openstack_service_name, :openstack_tenant,
10 10
                  :openstack_api_key, :openstack_username,
11 11
                  :current_user, :current_tenant,
12  
-                 :openstack_endpoint_type
  12
+                 :openstack_endpoint_type, :openstack_region
13 13
 
14 14
       model_path 'fog/openstack/models/volume'
15 15
 
@@ -125,6 +125,7 @@ def initialize(options={})
125 125
           @openstack_must_reauthenticate  = false
126 126
           @openstack_service_type         = options[:openstack_service_type] || ['volume']
127 127
           @openstack_service_name         = options[:openstack_service_name]
  128
+          @openstack_region               = options[:openstack_region]
128 129
 
129 130
           @openstack_endpoint_type        = options[:openstack_endpoint_type] || 'adminURL'
130 131
           @connection_options = options[:connection_options] || {}
@@ -188,6 +189,7 @@ def request(params)
188 189
         def authenticate
189 190
           if !@openstack_management_url || @openstack_must_reauthenticate
190 191
             options = {
  192
+              :openstack_region   => @openstack_region,
191 193
               :openstack_tenant   => @openstack_tenant,
192 194
               :openstack_api_key  => @openstack_api_key,
193 195
               :openstack_username => @openstack_username,
54  tests/openstack/models/compute/security_group_tests.rb
... ...
@@ -0,0 +1,54 @@
  1
+Shindo.tests("Fog::Compute[:openstack] | security_group", ['openstack']) do
  2
+  tests('success') do
  3
+    begin
  4
+      fog = Fog::Compute[:openstack]
  5
+
  6
+      security_group = fog.security_groups.create(
  7
+        :name        => 'my_group',
  8
+        :description => 'my group'
  9
+      )
  10
+
  11
+      tests('#create').succeeds do
  12
+        security_group = fog.security_groups.create(
  13
+          :name        => 'my_group',
  14
+          :description => 'my group'
  15
+        )
  16
+
  17
+        returns('my_group') { security_group.name }
  18
+        returns('my group') { security_group.description }
  19
+        returns([])         { security_group.security_group_rules }
  20
+        returns(true)       { security_group.tenant_id != nil }
  21
+      end
  22
+
  23
+      tests('#rules').succeeds do
  24
+        tests("#create").succeeds do
  25
+          rules_count = security_group.security_group_rules.count
  26
+          rule        = security_group.security_group_rules.create(
  27
+            :parent_group_id => security_group.id,
  28
+            :ip_protocol     => 'tcp',
  29
+            :from_port       => 1234,
  30
+            :to_port         => 1234,
  31
+            :ip_range        => { "cidr" => "0.0.0.0/0" }
  32
+          )
  33
+          returns(true) { security_group.security_group_rules.count == (rules_count + 1) }
  34
+          security_group_rule = security_group.security_group_rules.detect { |r| r.id == rule.id }
  35
+          returns(true) { security_group_rule.attributes == rule.attributes }
  36
+        end
  37
+
  38
+        tests("#destroy").succeeds do
  39
+          rule        = security_group.security_group_rules.create(
  40
+            :parent_group_id => security_group.id,
  41
+            :ip_protocol     => 'tcp',
  42
+            :from_port       => 1234,
  43
+            :to_port         => 1234,
  44
+            :ip_range        => { "cidr" => "0.0.0.0/0" }
  45
+          )
  46
+          rule.destroy
  47
+          returns(true) { rule.reload == nil }
  48
+        end
  49
+      end
  50
+    ensure
  51
+      security_group.destroy if security_group
  52
+    end
  53
+  end
  54
+end
19  tests/openstack/requests/compute/security_group_tests.rb
@@ -10,12 +10,12 @@
10 10
   }
11 11
 
12 12
   @security_group_rule_format = {
13  
-    "id"          => Integer,
14  
-    "from_port"   => Integer,
15  
-    "to_port"     => Integer,
16  
-    "ip_protocol" => String,
17  
-    "group"       => Hash,
18  
-    "ip_range"    => Hash,
  13
+    "id"              => Integer,
  14
+    "from_port"       => Integer,
  15
+    "to_port"         => Integer,
  16
+    "ip_protocol"     => String,
  17
+    "group"           => Hash,
  18
+    "ip_range"        => Hash,
19 19
     "parent_group_id" => Integer
20 20
   }
21 21
 
@@ -38,6 +38,13 @@
38 38
       Fog::Compute[:openstack].get_security_group(group_id).body
39 39
     end
40 40
 
  41
+    tests('#get_security_group_rule').formats({"security_group_rule" => @security_group_rule_format}) do
  42
+      parent_group_id = Fog::Compute[:openstack].list_security_groups.body['security_groups'].last['id']
  43
+      Fog::Compute[:openstack].create_security_group_rule(parent_group_id, "tcp", 2222, 3333, "20.20.20.20/24").body
  44
+      rule_id = Fog::Compute[:openstack].list_security_groups.body['security_groups'].last['rules'].first['id']
  45
+      Fog::Compute[:openstack].get_security_group_rule(rule_id).body
  46
+    end
  47
+
41 48
     tests('#delete_security_group_rule(security_group_rule_id)').succeeds do
42 49
       security_group_rule_id = Fog::Compute[:openstack].list_security_groups.body['security_groups'].last['rules'].last['id']
43 50
       Fog::Compute[:openstack].delete_security_group_rule(security_group_rule_id)
16  tests/openstack/requests/network/network_tests.rb
... ...
@@ -1,13 +1,13 @@
1 1
 Shindo.tests('Fog::Network[:openstack] | network requests', ['openstack']) do
2 2
 
3 3
   @network_format = {
4  
-    'id'                        => String,
5  
-    'name'                      => String,
6  
-    'subnets'                   => Array,
7  
-    'shared'                    => Fog::Boolean,
8  
-    'status'                    => String,
9  
-    'admin_state_up'            => Fog::Boolean,
10  
-    'tenant_id'                 => String
  4
+    'id'              => String,
  5
+    'name'            => String,
  6
+    'subnets'         => Array,
  7
+    'shared'          => Fog::Boolean,
  8
+    'status'          => String,
  9
+    'admin_state_up'  => Fog::Boolean,
  10
+    'tenant_id'       => String,
11 11
   }
12 12
 
13 13
   @network_format_extensions = {
@@ -98,7 +98,7 @@
98 98
       Fog::Network[:openstack].delete_network(0)
99 99
     end
100 100
   end
101  
-      
  101
+
102 102
   # Cleaning up the mess
103 103
   Fog::Network[:openstack].networks.each do |n|
104 104
     Fog::Network[:openstack].delete_network(n.id)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.