[Python-modules-commits] [proxmoxer] 01/04: Import proxmoxer_1.0.2.orig.tar.gz

Elena Grandi valhalla-guest at moszumanska.debian.org
Sun Dec 3 19:59:12 UTC 2017


This is an automated email from the git hooks/post-receive script.

valhalla-guest pushed a commit to branch master
in repository proxmoxer.

commit 597f68316f1599a20c49f6c64f1e3fde136bb7d2
Author: Elena ``of Valhalla'' Grandi <valhalla at trueelena.org>
Date:   Sun Dec 3 16:56:57 2017 +0100

    Import proxmoxer_1.0.2.orig.tar.gz
---
 LICENSE.txt                           |  21 +++++
 MANIFEST.in                           |   4 +
 PKG-INFO                              |  32 ++++---
 README.rst                            |   9 ++
 README.txt                            |  30 +++---
 proxmoxer.egg-info/PKG-INFO           |  32 ++++---
 proxmoxer.egg-info/SOURCES.txt        |  10 +-
 proxmoxer.egg-info/top_level.txt      |   1 +
 proxmoxer/__init__.py                 |   2 +-
 proxmoxer/backends/https.py           |   6 +-
 setup.py                              |   2 +-
 {proxmoxer => tests}/__init__.py      |   2 -
 {proxmoxer => tests/base}/__init__.py |   2 -
 tests/base/base_ssh_suite.py          | 166 ++++++++++++++++++++++++++++++++++
 tests/https_tests.py                  | 121 +++++++++++++++++++++++++
 tests/openssh_tests.py                |  29 ++++++
 tests/paramiko_tests.py               |  65 +++++++++++++
 17 files changed, 489 insertions(+), 45 deletions(-)

diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..4635d95
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2013 Oleg Butovich
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..976525a
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,4 @@
+include LICENSE.txt
+include README.txt
+include README.rst
+global-exclude *.orig *.pyc *.log *.swp
diff --git a/PKG-INFO b/PKG-INFO
index 3f87025..55eeafa 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: proxmoxer
-Version: 1.0.0
+Version: 1.0.2
 Summary: Python Wrapper for the Proxmox 2.x API (HTTP and SSH)
 Home-page: https://github.com/swayf/proxmoxer
 Author: Oleg Butovich
@@ -120,19 +120,18 @@ Description: =========================================
             pprint(node.storage.local.content.get())
         
         
-        Example of creation of openvz container::
+        Example of creation of lxc container::
         
             node = proxmox.nodes('proxmox_node')
-            node.openvz.create(vmid=202,
-                               ostemplate='local:vztmpl/debian-6-turnkey-core_12.0-1_i386.tar.gz',
-                               hostname='turnkey',
-                               storage='local',
-                               memory=512,
-                               swap=512,
-                               cpus=1,
-                               disk=4,
-                               password='secret',
-                               ip_address='10.0.0.202')
+            node.lxc.create(vmid=202,
+                ostemplate='local:vztmpl/debian-9.0-standard_20170530_amd64.tar.gz',
+                hostname='debian-stretch',
+                storage='local',
+                memory=512,
+                swap=512,
+                cores=1,
+                password='secret',
+                net0='name=eth0,bridge=vmbr0,ip=192.168.22.1/20,gw=192.168.16.1')
         
         Example of template upload::
         
@@ -164,6 +163,15 @@ Description: =========================================
         History
         -------
         
+        1.0.2 (2017-12-02)
+        ..................
+        * Tarball repackaged with tests
+        
+        1.0.1 (2017-12-02)
+        ..................
+        * LICENSE file now included in tarball
+        * Added verify_ssl parameter to ProxmoxHTTPAuth (`Walter Doekes <https://github.com/wdoekes>`_)
+        
         1.0.0 (2017-11-12)
         ..................
         * Update Proxmoxer readme (`Emmanuel Kasper <https://github.com/EmmanuelKasper>`_)
diff --git a/README.rst b/README.rst
index 8c7dcfa..bd639c7 100644
--- a/README.rst
+++ b/README.rst
@@ -168,6 +168,15 @@ Roadmap
 History
 -------
 
+1.0.2 (2017-12-02)
+..................
+* Tarball repackaged with tests
+
+1.0.1 (2017-12-02)
+..................
+* LICENSE file now included in tarball
+* Added verify_ssl parameter to ProxmoxHTTPAuth (`Walter Doekes <https://github.com/wdoekes>`_)
+
 1.0.0 (2017-11-12)
 ..................
 * Update Proxmoxer readme (`Emmanuel Kasper <https://github.com/EmmanuelKasper>`_)
diff --git a/README.txt b/README.txt
index 213a225..cf8eb31 100644
--- a/README.txt
+++ b/README.txt
@@ -111,19 +111,18 @@ or the with same results
     pprint(node.storage.local.content.get())
 
 
-Example of creation of openvz container::
+Example of creation of lxc container::
 
     node = proxmox.nodes('proxmox_node')
-    node.openvz.create(vmid=202,
-                       ostemplate='local:vztmpl/debian-6-turnkey-core_12.0-1_i386.tar.gz',
-                       hostname='turnkey',
-                       storage='local',
-                       memory=512,
-                       swap=512,
-                       cpus=1,
-                       disk=4,
-                       password='secret',
-                       ip_address='10.0.0.202')
+    node.lxc.create(vmid=202,
+        ostemplate='local:vztmpl/debian-9.0-standard_20170530_amd64.tar.gz',
+        hostname='debian-stretch',
+        storage='local',
+        memory=512,
+        swap=512,
+        cores=1,
+        password='secret',
+        net0='name=eth0,bridge=vmbr0,ip=192.168.22.1/20,gw=192.168.16.1')
 
 Example of template upload::
 
@@ -155,6 +154,15 @@ Roadmap
 History
 -------
 
+1.0.2 (2017-12-02)
+..................
+* Tarball repackaged with tests
+
+1.0.1 (2017-12-02)
+..................
+* LICENSE file now included in tarball
+* Added verify_ssl parameter to ProxmoxHTTPAuth (`Walter Doekes <https://github.com/wdoekes>`_)
+
 1.0.0 (2017-11-12)
 ..................
 * Update Proxmoxer readme (`Emmanuel Kasper <https://github.com/EmmanuelKasper>`_)
diff --git a/proxmoxer.egg-info/PKG-INFO b/proxmoxer.egg-info/PKG-INFO
index 3f87025..55eeafa 100644
--- a/proxmoxer.egg-info/PKG-INFO
+++ b/proxmoxer.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: proxmoxer
-Version: 1.0.0
+Version: 1.0.2
 Summary: Python Wrapper for the Proxmox 2.x API (HTTP and SSH)
 Home-page: https://github.com/swayf/proxmoxer
 Author: Oleg Butovich
@@ -120,19 +120,18 @@ Description: =========================================
             pprint(node.storage.local.content.get())
         
         
-        Example of creation of openvz container::
+        Example of creation of lxc container::
         
             node = proxmox.nodes('proxmox_node')
-            node.openvz.create(vmid=202,
-                               ostemplate='local:vztmpl/debian-6-turnkey-core_12.0-1_i386.tar.gz',
-                               hostname='turnkey',
-                               storage='local',
-                               memory=512,
-                               swap=512,
-                               cpus=1,
-                               disk=4,
-                               password='secret',
-                               ip_address='10.0.0.202')
+            node.lxc.create(vmid=202,
+                ostemplate='local:vztmpl/debian-9.0-standard_20170530_amd64.tar.gz',
+                hostname='debian-stretch',
+                storage='local',
+                memory=512,
+                swap=512,
+                cores=1,
+                password='secret',
+                net0='name=eth0,bridge=vmbr0,ip=192.168.22.1/20,gw=192.168.16.1')
         
         Example of template upload::
         
@@ -164,6 +163,15 @@ Description: =========================================
         History
         -------
         
+        1.0.2 (2017-12-02)
+        ..................
+        * Tarball repackaged with tests
+        
+        1.0.1 (2017-12-02)
+        ..................
+        * LICENSE file now included in tarball
+        * Added verify_ssl parameter to ProxmoxHTTPAuth (`Walter Doekes <https://github.com/wdoekes>`_)
+        
         1.0.0 (2017-11-12)
         ..................
         * Update Proxmoxer readme (`Emmanuel Kasper <https://github.com/EmmanuelKasper>`_)
diff --git a/proxmoxer.egg-info/SOURCES.txt b/proxmoxer.egg-info/SOURCES.txt
index 015712f..75a2c92 100644
--- a/proxmoxer.egg-info/SOURCES.txt
+++ b/proxmoxer.egg-info/SOURCES.txt
@@ -1,3 +1,5 @@
+LICENSE.txt
+MANIFEST.in
 README.rst
 README.txt
 setup.py
@@ -11,4 +13,10 @@ proxmoxer/backends/__init__.py
 proxmoxer/backends/base_ssh.py
 proxmoxer/backends/https.py
 proxmoxer/backends/openssh.py
-proxmoxer/backends/ssh_paramiko.py
\ No newline at end of file
+proxmoxer/backends/ssh_paramiko.py
+tests/__init__.py
+tests/https_tests.py
+tests/openssh_tests.py
+tests/paramiko_tests.py
+tests/base/__init__.py
+tests/base/base_ssh_suite.py
\ No newline at end of file
diff --git a/proxmoxer.egg-info/top_level.txt b/proxmoxer.egg-info/top_level.txt
index 10b38c4..fa9bbcc 100644
--- a/proxmoxer.egg-info/top_level.txt
+++ b/proxmoxer.egg-info/top_level.txt
@@ -1 +1,2 @@
 proxmoxer
+tests
diff --git a/proxmoxer/__init__.py b/proxmoxer/__init__.py
index 79fc064..a7cd49c 100644
--- a/proxmoxer/__init__.py
+++ b/proxmoxer/__init__.py
@@ -1,6 +1,6 @@
 __author__ = 'Oleg Butovich'
 __copyright__ = '(c) Oleg Butovich 2013-2017'
-__version__ = '1.0.0'
+__version__ = '1.0.2'
 __licence__ = 'MIT'
 
 from .core import *
diff --git a/proxmoxer/backends/https.py b/proxmoxer/backends/https.py
index cfbb708..b870195 100644
--- a/proxmoxer/backends/https.py
+++ b/proxmoxer/backends/https.py
@@ -38,9 +38,9 @@ class AuthenticationError(Exception):
 
 
 class ProxmoxHTTPAuth(AuthBase):
-    def __init__(self, base_url, username, password):
+    def __init__(self, base_url, username, password, verify_ssl=False):
         response_data = requests.post(base_url + "/access/ticket",
-                                      verify=False,
+                                      verify=verify_ssl,
                                       data={"username": username, "password": password}).json()["data"]
         if response_data is None:
             raise AuthenticationError("Couldn't authenticate user: {0} to {1}".format(username, base_url + "/access/ticket"))
@@ -113,7 +113,7 @@ class Backend(object):
         if auth_token is not None:
             self.auth = ProxmoxHTTPTokenAuth(auth_token, csrf_token)
         else:
-            self.auth = ProxmoxHTTPAuth(self.base_url, user, password)
+            self.auth = ProxmoxHTTPAuth(self.base_url, user, password, verify_ssl)
         self.verify_ssl = verify_ssl
         self.mode = mode
         self.timeout = timeout
diff --git a/setup.py b/setup.py
index e717845..04b6633 100644
--- a/setup.py
+++ b/setup.py
@@ -33,7 +33,7 @@ setup(
     url = 'https://github.com/swayf/proxmoxer',
     download_url = 'http://pypi.python.org/pypi/proxmoxer',
     keywords = ['proxmox', 'api'],
-    packages=['proxmoxer', 'proxmoxer.backends'],
+    packages=['proxmoxer', 'proxmoxer.backends', 'tests', 'tests.base'],
     classifiers = [ #http://pypi.python.org/pypi?%3Aaction=list_classifiers
         "Development Status :: 4 - Beta",
         "Programming Language :: Python",
diff --git a/proxmoxer/__init__.py b/tests/__init__.py
similarity index 69%
copy from proxmoxer/__init__.py
copy to tests/__init__.py
index 79fc064..923b0d1 100644
--- a/proxmoxer/__init__.py
+++ b/tests/__init__.py
@@ -1,6 +1,4 @@
 __author__ = 'Oleg Butovich'
 __copyright__ = '(c) Oleg Butovich 2013-2017'
-__version__ = '1.0.0'
 __licence__ = 'MIT'
 
-from .core import *
diff --git a/proxmoxer/__init__.py b/tests/base/__init__.py
similarity index 69%
copy from proxmoxer/__init__.py
copy to tests/base/__init__.py
index 79fc064..923b0d1 100644
--- a/proxmoxer/__init__.py
+++ b/tests/base/__init__.py
@@ -1,6 +1,4 @@
 __author__ = 'Oleg Butovich'
 __copyright__ = '(c) Oleg Butovich 2013-2017'
-__version__ = '1.0.0'
 __licence__ = 'MIT'
 
-from .core import *
diff --git a/tests/base/base_ssh_suite.py b/tests/base/base_ssh_suite.py
new file mode 100644
index 0000000..cbe6d07
--- /dev/null
+++ b/tests/base/base_ssh_suite.py
@@ -0,0 +1,166 @@
+__author__ = 'Oleg Butovich'
+__copyright__ = '(c) Oleg Butovich 2013-2017'
+__licence__ = 'MIT'
+
+from itertools import islice
+
+try:
+    import itertools.izip as zip
+except ImportError:
+    pass
+
+from nose.tools import eq_, ok_, raises
+from proxmoxer.core import ResourceException
+
+class BaseSSHSuite(object):
+    proxmox = None
+    client = None
+    session = None
+
+    def __init__(self, sudo=False):
+        self.sudo = sudo
+
+    def _split_cmd(self, cmd):
+        splitted = cmd.split()
+        if not self.sudo:
+            eq_(splitted[0], 'pvesh')
+        else:
+            eq_(splitted[0], 'sudo')
+            eq_(splitted[1], 'pvesh')
+            splitted.pop(0)
+        options_set = set((' '.join((k, v)) for k, v in
+                           zip(islice(splitted, 3, None, 2),
+                               islice(splitted, 4, None, 2))))
+        return ' '.join(splitted[1:3]), options_set
+
+    def _get_called_cmd(self):
+        raise NotImplementedError()
+
+    def _set_stdout(self, stdout):
+        raise NotImplementedError()
+
+    def _set_stderr(self, stderr):
+        raise NotImplementedError()
+
+    def test_get(self):
+        self._set_stdout("""
+            [
+               {
+                  "subdir" : "status"
+               },
+               {
+                  "subdir" : "content"
+               },
+               {
+                  "subdir" : "upload"
+               },
+               {
+                  "subdir" : "rrd"
+               },
+               {
+                  "subdir" : "rrddata"
+               }
+            ]""")
+        result = self.proxmox.nodes('proxmox').storage('local').get()
+        eq_(self._get_called_cmd(), self._called_cmd('pvesh get /nodes/proxmox/storage/local'))
+        eq_(result[0]['subdir'], 'status')
+        eq_(result[1]['subdir'], 'content')
+        eq_(result[2]['subdir'], 'upload')
+        eq_(result[3]['subdir'], 'rrd')
+        eq_(result[4]['subdir'], 'rrddata')
+
+    def test_delete(self):
+        self.proxmox.nodes('proxmox').openvz(100).delete()
+        eq_(self._get_called_cmd(), self._called_cmd('pvesh delete /nodes/proxmox/openvz/100'))
+        self.proxmox.nodes('proxmox').openvz('101').delete()
+        eq_(self._get_called_cmd(), self._called_cmd('pvesh delete /nodes/proxmox/openvz/101'))
+        self.proxmox.nodes('proxmox').openvz.delete('102')
+        eq_(self._get_called_cmd(), self._called_cmd('pvesh delete /nodes/proxmox/openvz/102'))
+
+    def test_post(self):
+        node = self.proxmox.nodes('proxmox')
+        node.openvz.create(vmid=800,
+                           ostemplate='local:vztmpl/debian-6-turnkey-core_12.0-1_i386.tar.gz',
+                           hostname='test',
+                           storage='local',
+                           memory=512,
+                           swap=512,
+                           cpus=1,
+                           disk=4,
+                           password='secret',
+                           ip_address='10.0.100.222')
+        cmd, options = self._split_cmd(self._get_called_cmd())
+        eq_(cmd, 'create /nodes/proxmox/openvz')
+        ok_('-cpus 1' in options)
+        ok_('-disk 4' in options)
+        ok_('-hostname test' in options)
+        ok_('-ip_address 10.0.100.222' in options)
+        ok_('-memory 512' in options)
+        ok_('-ostemplate local:vztmpl/debian-6-turnkey-core_12.0-1_i386.tar.gz' in options)
+        ok_('-password secret' in options)
+        ok_('-storage local' in options)
+        ok_('-swap 512' in options)
+        ok_('-vmid 800' in options)
+
+        node = self.proxmox.nodes('proxmox1')
+        node.openvz.post(vmid=900,
+                         ostemplate='local:vztmpl/debian-7-turnkey-core_12.0-1_i386.tar.gz',
+                         hostname='test1',
+                         storage='local1',
+                         memory=1024,
+                         swap=1024,
+                         cpus=2,
+                         disk=8,
+                         password='secret1',
+                         ip_address='10.0.100.111')
+        cmd, options = self._split_cmd(self._get_called_cmd())
+        eq_(cmd, 'create /nodes/proxmox1/openvz')
+        ok_('-cpus 2' in options)
+        ok_('-disk 8' in options)
+        ok_('-hostname test1' in options)
+        ok_('-ip_address 10.0.100.111' in options)
+        ok_('-memory 1024' in options)
+        ok_('-ostemplate local:vztmpl/debian-7-turnkey-core_12.0-1_i386.tar.gz' in options)
+        ok_('-password secret1' in options)
+        ok_('-storage local1' in options)
+        ok_('-swap 1024' in options)
+        ok_('-vmid 900' in options)
+
+    def test_put(self):
+        node = self.proxmox.nodes('proxmox')
+        node.openvz(101).config.set(cpus=4, memory=1024, ip_address='10.0.100.100', onboot=True)
+        cmd, options = self._split_cmd(self._get_called_cmd())
+        eq_(cmd, 'set /nodes/proxmox/openvz/101/config')
+        ok_('-memory 1024' in options)
+        ok_('-ip_address 10.0.100.100' in options)
+        ok_('-onboot True' in options)
+        ok_('-cpus 4' in options)
+
+        node = self.proxmox.nodes('proxmox1')
+        node.openvz('102').config.put(cpus=2, memory=512, ip_address='10.0.100.200', onboot=False)
+        cmd, options = self._split_cmd(self._get_called_cmd())
+        eq_(cmd, 'set /nodes/proxmox1/openvz/102/config')
+        ok_('-memory 512' in options)
+        ok_('-ip_address 10.0.100.200' in options)
+        ok_('-onboot False' in options)
+        ok_('-cpus 2' in options)
+
+    @raises(ResourceException)
+    def test_error(self):
+        self._set_stderr("500 whoops")
+        self.proxmox.nodes('proxmox').get()
+
+    def test_no_error_with_extra_output(self):
+        self._set_stderr("Extra output\n200 OK")
+        self.proxmox.nodes('proxmox').get()
+
+    @raises(ResourceException)
+    def test_error_with_extra_output(self):
+        self._set_stderr("Extra output\n500 whoops")
+        self.proxmox.nodes('proxmox').get()
+
+    def _called_cmd(self, cmd):
+        called_cmd = cmd
+        if self.sudo:
+            called_cmd = 'sudo ' + cmd
+        return called_cmd
diff --git a/tests/https_tests.py b/tests/https_tests.py
new file mode 100644
index 0000000..3efc1fc
--- /dev/null
+++ b/tests/https_tests.py
@@ -0,0 +1,121 @@
+__author__ = 'Oleg Butovich'
+__copyright__ = '(c) Oleg Butovich 2013-2017'
+__licence__ = 'MIT'
+
+from mock import patch, MagicMock
+from nose.tools import eq_, ok_
+from proxmoxer import ProxmoxAPI
+
+
+ at patch('requests.sessions.Session')
+def test_https_connection(req_session):
+    response = {'ticket': 'ticket',
+                'CSRFPreventionToken': 'CSRFPreventionToken'}
+    req_session.request.return_value = response
+    ProxmoxAPI('proxmox', user='root at pam', password='secret', port=123, verify_ssl=False)
+    call = req_session.return_value.request.call_args[1]
+    eq_(call['url'], 'https://proxmox:123/api2/json/access/ticket')
+    eq_(call['data'], {'username': 'root at pam', 'password': 'secret'})
+    eq_(call['method'], 'post')
+    eq_(call['verify'], False)
+
+
+class TestSuite():
+    proxmox = None
+    serializer = None
+    session = None
+
+    # noinspection PyMethodOverriding
+    @patch('requests.sessions.Session')
+    def setUp(self, session):
+        response = {'ticket': 'ticket',
+                    'CSRFPreventionToken': 'CSRFPreventionToken'}
+        session.request.return_value = response
+        self.proxmox = ProxmoxAPI('proxmox', user='root at pam', password='secret', port=123, verify_ssl=False)
+        self.serializer = MagicMock()
+        self.session = MagicMock()
+        self.session.request.return_value.status_code = 200
+        self.proxmox._store['session'] = self.session
+        self.proxmox._store['serializer'] = self.serializer
+
+    def test_get(self):
+        self.proxmox.nodes('proxmox').storage('local').get()
+        eq_(self.session.request.call_args[0], ('GET', 'https://proxmox:123/api2/json/nodes/proxmox/storage/local'))
+
+    def test_delete(self):
+        self.proxmox.nodes('proxmox').openvz(100).delete()
+        eq_(self.session.request.call_args[0], ('DELETE', 'https://proxmox:123/api2/json/nodes/proxmox/openvz/100'))
+        self.proxmox.nodes('proxmox').openvz('101').delete()
+        eq_(self.session.request.call_args[0], ('DELETE', 'https://proxmox:123/api2/json/nodes/proxmox/openvz/101'))
+
+    def test_post(self):
+        node = self.proxmox.nodes('proxmox')
+        node.openvz.create(vmid=800,
+                           ostemplate='local:vztmpl/debian-6-turnkey-core_12.0-1_i386.tar.gz',
+                           hostname='test',
+                           storage='local',
+                           memory=512,
+                           swap=512,
+                           cpus=1,
+                           disk=4,
+                           password='secret',
+                           ip_address='10.0.100.222')
+        eq_(self.session.request.call_args[0], ('POST', 'https://proxmox:123/api2/json/nodes/proxmox/openvz'))
+        ok_('data' in self.session.request.call_args[1])
+        data = self.session.request.call_args[1]['data']
+        eq_(data['cpus'], 1)
+        eq_(data['disk'], 4)
+        eq_(data['hostname'], 'test')
+        eq_(data['ip_address'], '10.0.100.222')
+        eq_(data['memory'], 512)
+        eq_(data['ostemplate'], 'local:vztmpl/debian-6-turnkey-core_12.0-1_i386.tar.gz')
+        eq_(data['password'], 'secret')
+        eq_(data['storage'], 'local')
+        eq_(data['swap'], 512)
+        eq_(data['vmid'], 800)
+
+        node = self.proxmox.nodes('proxmox1')
+        node.openvz.post(vmid=900,
+                         ostemplate='local:vztmpl/debian-7-turnkey-core_12.0-1_i386.tar.gz',
+                         hostname='test1',
+                         storage='local1',
+                         memory=1024,
+                         swap=1024,
+                         cpus=2,
+                         disk=8,
+                         password='secret1',
+                         ip_address='10.0.100.111')
+        eq_(self.session.request.call_args[0], ('POST', 'https://proxmox:123/api2/json/nodes/proxmox1/openvz'))
+        ok_('data' in self.session.request.call_args[1])
+        data = self.session.request.call_args[1]['data']
+        eq_(data['cpus'], 2)
+        eq_(data['disk'], 8)
+        eq_(data['hostname'], 'test1')
+        eq_(data['ip_address'], '10.0.100.111')
+        eq_(data['memory'], 1024)
+        eq_(data['ostemplate'], 'local:vztmpl/debian-7-turnkey-core_12.0-1_i386.tar.gz')
+        eq_(data['password'], 'secret1')
+        eq_(data['storage'], 'local1')
+        eq_(data['swap'], 1024)
+        eq_(data['vmid'], 900)
+
+    def test_put(self):
+        node = self.proxmox.nodes('proxmox')
+        node.openvz(101).config.set(cpus=4, memory=1024, ip_address='10.0.100.100', onboot=True)
+        eq_(self.session.request.call_args[0], ('PUT', 'https://proxmox:123/api2/json/nodes/proxmox/openvz/101/config'))
+        data = self.session.request.call_args[1]['data']
+        eq_(data['cpus'], 4)
+        eq_(data['memory'], 1024)
+        eq_(data['ip_address'], '10.0.100.100')
+        eq_(data['onboot'], True)
+
+        node = self.proxmox.nodes('proxmox1')
+        node.openvz(102).config.put(cpus=2, memory=512, ip_address='10.0.100.200', onboot=False)
+        eq_(self.session.request.call_args[0],
+            ('PUT', 'https://proxmox:123/api2/json/nodes/proxmox1/openvz/102/config'))
+        data = self.session.request.call_args[1]['data']
+        eq_(data['cpus'], 2)
+        eq_(data['memory'], 512)
+        eq_(data['ip_address'], '10.0.100.200')
+        eq_(data['onboot'], False)
+
diff --git a/tests/openssh_tests.py b/tests/openssh_tests.py
new file mode 100644
index 0000000..34cf094
--- /dev/null
+++ b/tests/openssh_tests.py
@@ -0,0 +1,29 @@
+__author__ = 'Oleg Butovich'
+__copyright__ = '(c) Oleg Butovich 2013-2017'
+__licence__ = 'MIT'
+
+from mock import patch
+from proxmoxer import ProxmoxAPI
+from tests.base.base_ssh_suite import BaseSSHSuite
+
+
+class TestOpenSSHSuite(BaseSSHSuite):
+    proxmox = None
+    client = None
+
+    # noinspection PyMethodOverriding
+    @patch('openssh_wrapper.SSHConnection')
+    def setUp(self, _):
+        self.proxmox = ProxmoxAPI('proxmox', user='root', backend='openssh', port=123)
+        self.client = self.proxmox._store['session'].ssh_client
+        self._set_stderr('200 OK')
+        self._set_stdout('')
+
+    def _get_called_cmd(self):
+        return self.client.run.call_args[0][0]
+
+    def _set_stdout(self, stdout):
+        self.client.run.return_value.stdout = stdout
+
+    def _set_stderr(self, stderr):
+        self.client.run.return_value.stderr = stderr
diff --git a/tests/paramiko_tests.py b/tests/paramiko_tests.py
new file mode 100644
index 0000000..923c386
--- /dev/null
+++ b/tests/paramiko_tests.py
@@ -0,0 +1,65 @@
+__author__ = 'Oleg Butovich'
+__copyright__ = '(c) Oleg Butovich 2013-2017'
+__licence__ = 'MIT'
+
+from mock import patch
+from nose.tools import eq_
+from proxmoxer import ProxmoxAPI
+from .base.base_ssh_suite import BaseSSHSuite
+
+
+ at patch('paramiko.SSHClient')
+def test_paramiko_connection(_):
+    proxmox = ProxmoxAPI('proxmox', user='root', backend='ssh_paramiko', port=123)
+    session = proxmox._store['session']
+    eq_(session.ssh_client.connect.call_args[0], ('proxmox',))
+    eq_(session.ssh_client.connect.call_args[1], {'username': 'root',
+                                                  'allow_agent': True,
+                                                  'key_filename': None,
+                                                  'look_for_keys': True,
+                                                  'timeout': 5,
+                                                  'password': None,
+                                                  'port': 123})
+
+
+class TestParamikoSuite(BaseSSHSuite):
+
+    # noinspection PyMethodOverriding
+    @patch('paramiko.SSHClient')
+    def setUp(self, _):
+        self.proxmox = ProxmoxAPI('proxmox', user='root', backend='ssh_paramiko', port=123)
+        self.client = self.proxmox._store['session'].ssh_client
+        self.session = self.client.get_transport().open_session()
+        self._set_stderr('200 OK')
+        self._set_stdout('')
+
+    def _get_called_cmd(self):
+        return self.session.exec_command.call_args[0][0]
+
+    def _set_stdout(self, stdout):
+        self.session.makefile.return_value = [stdout]
+
+    def _set_stderr(self, stderr):
+        self.session.makefile_stderr.return_value = [stderr]
+
+
+class TestParamikoSuiteWithSudo(BaseSSHSuite):
+
+    # noinspection PyMethodOverriding
+    @patch('paramiko.SSHClient')
+    def setUp(self, _):
+        super(TestParamikoSuiteWithSudo, self).__init__(sudo=True)
+        self.proxmox = ProxmoxAPI('proxmox', user='root', backend='ssh_paramiko', port=123, sudo=True)
+        self.client = self.proxmox._store['session'].ssh_client
+        self.session = self.client.get_transport().open_session()
+        self._set_stderr('200 OK')
+        self._set_stdout('')
+
+    def _get_called_cmd(self):
+        return self.session.exec_command.call_args[0][0]
+
+    def _set_stdout(self, stdout):
+        self.session.makefile.return_value = [stdout]
+
+    def _set_stderr(self, stderr):
+        self.session.makefile_stderr.return_value = [stderr]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/proxmoxer.git



More information about the Python-modules-commits mailing list