~ubuntu-branches/ubuntu/vivid/sahara/vivid-proposed

« back to all changes in this revision

Viewing changes to sahara/tests/unit/plugins/hdp/hdp_test_base.py

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2014-09-24 16:34:46 UTC
  • Revision ID: package-import@ubuntu.com-20140924163446-8gu3zscu5e3n9lr2
Tags: upstream-2014.2~b3
ImportĀ upstreamĀ versionĀ 2014.2~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2013 Hortonworks, Inc.
 
2
#
 
3
# Licensed under the Apache License, Version 2.0 (the "License");
 
4
# you may not use this file except in compliance with the License.
 
5
# You may obtain a copy of the License at
 
6
#
 
7
#    http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
# Unless required by applicable law or agreed to in writing, software
 
10
# distributed under the License is distributed on an "AS IS" BASIS,
 
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 
12
# implied.
 
13
# See the License for the specific language governing permissions and
 
14
# limitations under the License.
 
15
 
 
16
import pkg_resources as pkg
 
17
 
 
18
from sahara.plugins.hdp import clusterspec as cs
 
19
from sahara import version
 
20
 
 
21
 
 
22
class TestServer:
 
23
    def __init__(self, hostname, role, img, flavor, public_ip, private_ip):
 
24
        self.inst_fqdn = hostname
 
25
        self.role = role
 
26
        self.instance_info = InstanceInfo(
 
27
            hostname, img, flavor, public_ip, private_ip)
 
28
        self.management_ip = public_ip
 
29
        self.public_ip = public_ip
 
30
        self.internal_ip = private_ip
 
31
        self.node_group = None
 
32
 
 
33
    def fqdn(self):
 
34
        return self.inst_fqdn
 
35
 
 
36
    def remote(self):
 
37
        return None
 
38
 
 
39
 
 
40
def get_instance_info(*args, **kwargs):
 
41
    return args[0].instance_info
 
42
 
 
43
 
 
44
def create_clusterspec(hdp_version='1.3.2'):
 
45
    version_suffix = hdp_version.replace('.', '_')
 
46
    cluster_config_file = pkg.resource_string(
 
47
        version.version_info.package,
 
48
        'plugins/hdp/versions/version_{0}/resources/'
 
49
        'default-cluster.template'.format(version_suffix))
 
50
 
 
51
    return cs.ClusterSpec(cluster_config_file, version=hdp_version)
 
52
 
 
53
 
 
54
class InstanceInfo:
 
55
    def __init__(self, hostname, image, flavor, management_ip, internal_ip):
 
56
        self.image = image
 
57
        self.flavor = flavor
 
58
        self.management_ip = management_ip
 
59
        self.internal_ip = internal_ip
 
60
 
 
61
 
 
62
class TestCluster():
 
63
    def __init__(self, node_groups):
 
64
        self.hadoop_version = None
 
65
        self.cluster_configs = {}
 
66
        self.node_groups = node_groups
 
67
        self.default_image_id = '11111'
 
68
 
 
69
 
 
70
class TestNodeGroup:
 
71
    def __init__(self, name, instances, node_processes, count=1):
 
72
        self.name = name
 
73
        self.instances = instances
 
74
        if instances:
 
75
            for i in instances:
 
76
                i.node_group = self
 
77
        self.node_processes = node_processes
 
78
        self.count = count
 
79
        self.id = name
 
80
        self.ng_storage_paths = []
 
81
 
 
82
    def storage_paths(self):
 
83
        return self.ng_storage_paths
 
84
 
 
85
 
 
86
class TestUserInputConfig:
 
87
    def __init__(self, tag, target, name):
 
88
        self.tag = tag
 
89
        self.applicable_target = target
 
90
        self.name = name
 
91
 
 
92
 
 
93
class TestRequest:
 
94
    def put(self, url, data=None, auth=None, headers=None):
 
95
        self.url = url
 
96
        self.data = data
 
97
        self.auth = auth
 
98
        self.headers = headers
 
99
        self.method = 'put'
 
100
 
 
101
        return TestResult(200)
 
102
 
 
103
    def post(self, url, data=None, auth=None, headers=None):
 
104
        self.url = url
 
105
        self.data = data
 
106
        self.auth = auth
 
107
        self.headers = headers
 
108
        self.method = 'post'
 
109
 
 
110
        return TestResult(201)
 
111
 
 
112
    def delete(self, url, auth=None, headers=None):
 
113
        self.url = url
 
114
        self.auth = auth
 
115
        self.data = None
 
116
        self.headers = headers
 
117
        self.method = 'delete'
 
118
 
 
119
        return TestResult(200)
 
120
 
 
121
 
 
122
class TestResult:
 
123
    def __init__(self, status):
 
124
        self.status_code = status
 
125
        self.text = ''
 
126
 
 
127
 
 
128
class TestUserInput:
 
129
    def __init__(self, config, value):
 
130
        self.config = config
 
131
        self.value = value