File: volume_connection_test.rb

package info (click to toggle)
ruby-openstack 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 452 kB
  • sloc: ruby: 3,217; makefile: 6
file content (136 lines) | stat: -rw-r--r-- 4,320 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
require File.dirname(__FILE__) + '/../test_helper'

class VolumeConnectionTest < Test::Unit::TestCase
  def volume_connection
    OpenStack::Volume::Connection.any_instance.stubs(:check_if_native).returns(true)

    conn_response = { 'x-server-management-url' => 'http://server-manage.example.com/path', 'x-auth-token' => 'dummy_token' }
    conn_response.stubs(code: '200', body: auth_server_json_response)
    server = mock(start: true, finish: true)
    server.stubs(post: conn_response, started?: true)
    Net::HTTP.stubs(:new).returns(server)
    OpenStack::Connection.create(
      username: 'test_account',
      api_key: 'AABBCCDD11',
      auth_url: 'http://a.b.c:35357/v2.0',
      service_type: 'volume'
    )
  end

  def auth_server_json_response
    %({
      "access": {
        "token": {
          "issued_at": "2016-02-04T15:23:30.918500",
          "expires": "2016-02-04T16:23:30Z",
          "id": "123",
          "tenant": {
            "description": "Tenant for the openstack services",
            "enabled": true,
            "id": "123",
            "name": "openstack"
          }
        },
        "serviceCatalog": [
          {
            "endpoints": [
              {
                "adminURL": "http://a.b.c:8776/v1/9bf44ea27d8b4573b2c590a8937b118f",
                "region": "RegionOne",
                "internalURL": "http://a.b.c:8776/v1/9bf44ea27d8b4573b2c590a8937b118f",
                "id": "066f938aa5344421bbbf4317d3f73b21",
                "publicURL": "http://a.b.c:8776/v1/9bf44ea27d8b4573b2c590a8937b118f"
              }
            ],
            "endpoints_links": [],
            "type": "volume",
            "name": "cinder"
          }
        ],
        "user": {
          "username": "test",
          "roles_links": [],
          "id": "37ee959016b6492ab096abb1d9961bda",
          "roles": [
            {
              "name": "admin"
            }
          ],
          "name": "test"
        },
        "metadata": {
          "is_admin": 0,
          "roles": [
            "a5f062de2c274dcfa651b544dd59a0ab"
          ]
        }
      }
    })
  end

  def setup
    @cinder = volume_connection
  end

  def test_list_volume_types
    json_response = %{{
      "volume_types": [
        {"extra_specs": {"volume_backend_name": "volumes-standard"}, "name": "slow", "id": "b3a104b6-fe70-4450-8681-e911a153f41f"},
        {"extra_specs": {"volume_backend_name": "volumes-speed"}, "name": "fast", "id": "0e278952-9baa-4aa8-88a7-fe8387f1d86c"}
      ]
    }}

    response = mock
    response.stubs(code: '200', body: json_response)
    @cinder.connection.stubs(:req).returns(response)

    types = @cinder.list_volume_types
    assert_equal types.size, 2
    assert_equal types[0][:name], 'slow'
    assert_equal types[0][:id], 'b3a104b6-fe70-4450-8681-e911a153f41f'
  end

  def test_get_quotas
    json_response = %{{
      "quota_set": {
        "volumes_slow": -1, "snapshots_slow": -1, "gigabytes_slow": -1,
        "volumes_fast": -1, "snapshots_fast": -1, "gigabytes_fast": -1,
        "volumes": 10, "snapshots": 10, "gigabytes": 100, "id": "1"
      }
    }}

    response = mock
    response.stubs(code: '200', body: json_response)
    @cinder.connection.stubs(:req).returns(response)

    quotas = @cinder.get_quotas(1)
    assert_equal quotas['id'], '1'
    assert_equal quotas['volumes'], 10
    assert_equal quotas['snapshots'], 10
    assert_equal quotas['gigabytes'], 100
    assert_equal quotas['volumes_slow'], -1
  end

  def test_update_quotas
    json_response = %{{
      "quota_set": {
        "volumes_slow": -1, "snapshots_slow": -1, "gigabytes_slow": 200,
        "volumes_fast": -1, "snapshots_fast": -1, "gigabytes_fast": 300,
        "volumes": 10, "snapshots": 10, "gigabytes": 500
      }
    }}

    response = mock
    response.stubs(code: '200', body: json_response)
    @cinder.connection.stubs(:req).returns(response)

    quota_set = { gigabytes: 500, gigabytes_slow: 200, gigabytes_fast: 300 }
    quotas = @cinder.update_quotas(1, quota_set)
    assert_equal quotas['volumes'], 10
    assert_equal quotas['snapshots'], 10
    assert_equal quotas['gigabytes'], 500
    assert_equal quotas['gigabytes_slow'], 200
    assert_equal quotas['gigabytes_fast'], 300
    assert_equal quotas['volumes_slow'], -1
  end
end