NSB: move interface probe to VNF, and attempt driver-only probe first
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / vnf_ssh_helper.py
1 # Copyright (c) 2016-2017 Intel Corporation
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 implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import logging
16 import os
17
18 from six.moves import StringIO
19
20 from yardstick.network_services.constants import REMOTE_TMP
21 from yardstick.ssh import AutoConnectSSH
22
23 LOG = logging.getLogger(__name__)
24
25
26 class VnfSshHelper(AutoConnectSSH):
27
28     def __init__(self, node, bin_path, wait=None):
29         self.node = node
30         kwargs = self.args_from_node(self.node)
31         if wait:
32             # if wait is defined here we want to override
33             kwargs['wait'] = wait
34
35         super(VnfSshHelper, self).__init__(**kwargs)
36         self.bin_path = bin_path
37
38     @staticmethod
39     def get_class():
40         # must return static class name, anything else refers to the calling class
41         # i.e. the subclass, not the superclass
42         return VnfSshHelper
43
44     def copy(self):
45         # this copy constructor is different from SSH classes, since it uses node
46         return self.get_class()(self.node, self.bin_path)
47
48     def upload_config_file(self, prefix, content):
49         cfg_file = os.path.join(REMOTE_TMP, prefix)
50         LOG.debug(content)
51         file_obj = StringIO(content)
52         self.put_file_obj(file_obj, cfg_file)
53         return cfg_file
54
55     def join_bin_path(self, *args):
56         return os.path.join(self.bin_path, *args)
57
58     def provision_tool(self, tool_path=None, tool_file=None):
59         if tool_path is None:
60             tool_path = self.bin_path
61         return super(VnfSshHelper, self).provision_tool(tool_path, tool_file)