File: server_connection.py

package info (click to toggle)
openstack-trove 2014.1.3-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,752 kB
  • ctags: 6,663
  • sloc: python: 37,317; xml: 1,485; sh: 281; makefile: 49
file content (54 lines) | stat: -rw-r--r-- 2,126 bytes parent folder | download
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
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from trove import tests
from trove.tests import util
from trove.tests.util.users import Requirements


def create_server_connection(instance_id):
    if util.test_config.use_local_ovz:
        return OpenVZServerConnection(instance_id)
    return ServerSSHConnection(instance_id)


class ServerSSHConnection(object):
    def __init__(self, instance_id):
        self.instance_id = instance_id
        req_admin = Requirements(is_admin=True)
        self.user = util.test_config.users.find_user(req_admin)
        self.dbaas_admin = util.create_dbaas_client(self.user)
        self.instance = self.dbaas_admin.management.show(self.instance_id)
        self.ip_address = self.instance.ip[0]

    def execute(self, cmd):
        exe_cmd = "%s %s %s" % (tests.SSH_CMD, self.ip_address, cmd)
        print("RUNNING COMMAND: %s" % exe_cmd)
        return util.process(exe_cmd)


class OpenVZServerConnection(object):
    def __init__(self, instance_id):
        self.instance_id = instance_id
        req_admin = Requirements(is_admin=True)
        self.user = util.test_config.users.find_user(req_admin)
        self.dbaas_admin = util.create_dbaas_client(self.user)
        self.instance = self.dbaas_admin.management.show(self.instance_id)
        self.instance_local_id = self.instance.server["local_id"]

    def execute(self, cmd):
        exe_cmd = "sudo vzctl exec %s %s" % (self.instance_local_id, cmd)
        print("RUNNING COMMAND: %s" % exe_cmd)
        return util.process(exe_cmd)