Merge pull request #8 from pycontribs/match-api-expectations-and-fixes

Match API expectations
This commit is contained in:
decentral1se 2019-11-16 09:15:17 +07:00 committed by GitHub
commit 342abb43bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 17 additions and 87 deletions

View File

@ -13,4 +13,4 @@ Install
.. code-block:: bash .. code-block:: bash
$ pip install 'molecule[hetznercloud]' $ pip install molecule-hetznercloud

View File

@ -28,63 +28,6 @@ log = logger.get_logger(__name__)
class HetznerCloud(Driver): class HetznerCloud(Driver):
"""
The class responsible for managing `Hetzner Cloud`_ instances.
`Hetzner Cloud`_ is **not** the default driver used in Molecule.
Molecule leverages Ansible's `hcloud_server module`_, by mapping variables
from ``molecule.yml`` into ``create.yml`` and ``destroy.yml``.
.. important::
The ``hcloud_server`` module is only available in Ansible >= 2.8.
.. _`hcloud_server module`: https://docs.ansible.com/ansible/devel/modules/hcloud_server_module.html#hcloud-server-module
.. code-block:: yaml
driver:
name: hetznercloud
platforms:
- name: instance
server_type: cx11
image: debian-9
.. code-block:: bash
$ pip install 'molecule[hetznercloud]'
Change the options passed to the ssh client.
.. code-block:: yaml
driver:
name: hetznercloud
ssh_connection_options:
- '-o ControlPath=~/.ansible/cp/%r@%h-%p'
.. important::
The Hetzner Cloud driver implementation uses the Parmiko transport
provided by Ansible to avoid issues of connection hanging and
indefinite polling as experienced with the default OpenSSh based
transport.
.. important::
Molecule does not merge lists, when overriding the developer must
provide all options.
Provide the files Molecule will preserve upon each subcommand execution.
.. code-block:: yaml
driver:
name: hetznercloud
safe_files:
- foo
""" # noqa
def __init__(self, config=None): def __init__(self, config=None):
super(HetznerCloud, self).__init__(config) super(HetznerCloud, self).__init__(config)
self._name = "hetznercloud" self._name = "hetznercloud"
@ -137,8 +80,6 @@ class HetznerCloud(Driver):
except StopIteration: except StopIteration:
return {} return {}
except IOError: except IOError:
# Instance has yet to be provisioned , therefore the
# instance_config is not on disk.
return {} return {}
def template_dir(self): def template_dir(self):
@ -165,8 +106,8 @@ class HetznerCloud(Driver):
except ImportError: except ImportError:
msg = ( msg = (
"Missing Hetzner Cloud driver dependency. Please " "Missing Hetzner Cloud driver dependency. Please "
"install via 'molecule[hetznercloud]' or refer to " "install the 'molecule-hetznercloud' package or "
"your INSTALL.rst driver documentation file" "refer to your INSTALL.rst driver documentation file"
) )
sysexit_with_message(msg) sysexit_with_message(msg)

View File

@ -21,6 +21,7 @@
import os import os
import pytest import pytest
import sh import sh
from molecule.scenario import ephemeral_directory from molecule.scenario import ephemeral_directory
@ -168,19 +169,7 @@ def test_command_idempotence(scenario_to_test, with_scenario, scenario_name):
pytest.helpers.idempotence(scenario_name) pytest.helpers.idempotence(scenario_name)
@pytest.mark.parametrize( @pytest.mark.parametrize("driver_name", [("hetznercloud")], indirect=["driver_name"])
"driver_name",
[
("digitalocean"),
("docker"),
("ec2"),
("gce"),
("linode"),
("openstack"),
("vagrant"),
],
indirect=["driver_name"],
)
def test_command_init_role(temp_dir, driver_name, skip_test): def test_command_init_role(temp_dir, driver_name, skip_test):
pytest.helpers.init_role(temp_dir, driver_name) pytest.helpers.init_role(temp_dir, driver_name)

View File

@ -2,7 +2,7 @@
dependency: dependency:
name: galaxy name: galaxy
driver: driver:
name: docker name: hetznercloud
lint: lint:
name: yamllint name: yamllint
platforms: platforms:

View File

@ -18,22 +18,21 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
from uuid import uuid4
import copy import copy
import functools import functools
import os import os
import shutil import shutil
from uuid import uuid4
import pytest
from molecule import config, util
try: try:
from pathlib import Path from pathlib import Path
except ImportError: except ImportError:
from pathlib2 import Path from pathlib2 import Path
import pytest
from molecule import util
from molecule import config
@pytest.helpers.register @pytest.helpers.register
def write_molecule_file(filename, data): def write_molecule_file(filename, data):
@ -55,7 +54,7 @@ def _molecule_dependency_galaxy_section_data():
@pytest.fixture @pytest.fixture
def _molecule_driver_section_data(): def _molecule_driver_section_data():
return {"driver": {"name": "docker", "options": {"managed": True}}} return {"driver": {"name": "hetznercloud", "options": {"managed": True}}}
@pytest.fixture @pytest.fixture

View File

@ -46,7 +46,7 @@ def _instance(_base_class):
def _command_args(): def _command_args():
return { return {
"dependency_name": "galaxy", "dependency_name": "galaxy",
"driver_name": "docker", "driver_name": "hetznercloud",
"lint_name": "yamllint", "lint_name": "yamllint",
"provisioner_name": "ansible", "provisioner_name": "ansible",
"scenario_name": "default", "scenario_name": "default",

View File

@ -21,13 +21,14 @@
import os import os
import pytest import pytest
from molecule import config from molecule import config
from molecule_hetznercloud import hetznercloud from molecule_hetznercloud import driver
@pytest.fixture @pytest.fixture
def hetznercloud_instance(patched_config_validate, config_instance): def hetznercloud_instance(patched_config_validate, config_instance):
return hetznercloud.HetznerCloud(config_instance) return driver.HetznerCloud(config_instance)
def test_hetznercloud_config_gives_config_object(hetznercloud_instance): def test_hetznercloud_config_gives_config_object(hetznercloud_instance):

View File

@ -33,7 +33,7 @@ def _molecule_file():
os.path.pardir, os.path.pardir,
os.path.pardir, os.path.pardir,
"resources", "resources",
"molecule_docker.yml", "molecule_hetznercloud.yml",
) )