Skip to content

Commit

Permalink
Adcm 1803 add fixture sdk_client_with_objects_ss (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
annademina authored Jun 28, 2021
1 parent e3832e6 commit 26ba259
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
packages=find_packages(where="src"),
package_dir={"": "src"},
include_package_data=True,
version="4.3.0",
version="4.3.1",
# the following makes a plugin available to pytest
entry_points={"pytest11": ["adcm_pytest_plugin = adcm_pytest_plugin.plugin"]},
# custom PyPI classifier for pytest plugins
Expand Down
40 changes: 36 additions & 4 deletions src/adcm_pytest_plugin/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# 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.

import socket
import time
import uuid
Expand All @@ -28,6 +27,7 @@
from allure_pytest.listener import AllureListener
from requests.exceptions import ReadTimeout as DockerReadTimeout

from adcm_pytest_plugin import utils
from .docker_utils import (
ADCM,
ADCMInitializer,
Expand All @@ -41,6 +41,8 @@
)
from .utils import check_mutually_exclusive, remove_host

DATADIR = utils.get_data_dir(__file__)

__all__ = [
"image",
"cmd_opts",
Expand Down Expand Up @@ -68,17 +70,14 @@ def image(request, cmd_opts, adcm_api_credentials):
"""That fixture creates ADCM container, waits until
a database becomes initialised and stores that as images
with random tag and name local/adcminit
That can be useful to use that fixture to make ADCM's
container startup time shorter.
Operates with cmd-opts:
'--staticimage INIT_IMAGE'
'--adcm-image IMAGE'
'--remote-docker HOST:PORT'
'--dontstop'
'--nopull'
Fixture returns list:
repo, tag
"""
Expand Down Expand Up @@ -311,3 +310,36 @@ def sdk_client_ss(adcm_ss: ADCM, adcm_api_credentials) -> ADCMClient:
def cmd_opts(request):
"""Returns pytest request options object"""
return request.config.option


@allure.title("Add dummy objects to ADCM")
def _sdk_client_with_objects_ss(sdk_client):
"""Returns ADCMClient with ADCM objects"""
with allure.step("Create provider"):
provider_bundle = sdk_client.upload_from_fs(utils.get_data_dir(__file__, "provider"))
provider = provider_bundle.provider_prototype().provider_create("Some provider")
with allure.step("Create cluster for the further import"):
cluster_to_import_bundle = sdk_client.upload_from_fs(utils.get_data_dir(__file__, "cluster_to_import"))
cluster_to_import = cluster_to_import_bundle.cluster_prototype().cluster_create(name="Dummy cluster to import")
with allure.step("Create a cluster with service"):
cluster_bundle = sdk_client.upload_from_fs(utils.get_data_dir(__file__, "cluster_with_service"))
cluster = cluster_bundle.cluster_prototype().cluster_create(name="Cluster with services")
cluster.bind(cluster_to_import)
with allure.step("Add services"):
service_first = cluster.service_add(name="Dummy service")
service_second = cluster.service_add(name="Second service")
with allure.step("Add hosts"):
host_first = provider.host_create("host_in_cluster")
host_second = provider.host_create("host_in_cluster_second")
cluster.host_add(host_first)
cluster.host_add(host_second)
with allure.step("Set components"):
cluster.hostcomponent_set(
(host_first, service_first.component(name="first")),
(host_second, service_first.component(name="second")),
(host_second, service_second.component(name="third")),
)
with allure.step("Run task"):
task = cluster.action(name="action_on_cluster").run()
task.wait()
return sdk_client
33 changes: 33 additions & 0 deletions src/adcm_pytest_plugin/fixtures_data/cluster_to_import/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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.

- type: cluster
name: Dummy cluster to import
version: 2.5
config:
required:
type: integer
required: true
default: 15
str-key:
default: value
type: string
required: false
int_key:
type: integer
required: false
default: 150

export:
- required
- str-key
- int_key
143 changes: 143 additions & 0 deletions src/adcm_pytest_plugin/fixtures_data/cluster_with_service/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# 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.

- type: cluster
name: Dummy cluster
version: 1.5
import:
Dummy cluster to import:
versions:
max: 3.0
min: 2.2
config:
- name: string
type: string
required: true
default: string
actions:
action_on_cluster:
type: job
script: dummy_action.yaml
script_type: ansible
states:
available:
- created
on_success: installed

- type: service
name: Dummy service
version: 1.5
components:
first:
config:
- name: string
type: string
required: true
default: string
actions:
component_first_action:
type: job
script: dummy_action.yaml
script_type: ansible
states:
available:
- created
on_success: installed

action_on_host_state_installed:
type: job
script: dummy_action.yaml
script_type: ansible
host_action: true
states:
available:
- installed

action_on_host_multijob:
type: task
scripts:
- name: part1
script_type: ansible
script: dummy_action.yaml
- name: part2
script_type: ansible
script: dummy_action.yaml
states:
available:
- created

second:
config:
- name: string
type: string
required: true
default: string
actions:
switch_component_state:
type: job
script: dummy_action.yaml
script_type: ansible
states:
available:
- created
on_success: installed
actions:
action_on_host:
type: job
script: dummy_action.yaml
script_type: ansible
host_action: true
states:
available:
- created

action_on_host_state_installed:
type: job
script: dummy_action.yaml
script_type: ansible
host_action: true
states:
available:
- installed

action_on_host_multijob:
type: task
scripts:
- name: part1
script_type: ansible
script: dummy_action.yaml
- name: part2
script_type: ansible
script: dummy_action.yaml
host_action: true
states:
available:
- created

- type: service
name: Second service
version: 1.5
config:
- name: string
type: string
required: false
default: string
actions:
job:
script: service_action.yaml
script_type: ansible
type: job
states:
available:
- created
components:
third:
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.
---
- name: Dummy action
hosts: all
connection: local
gather_facts: no

tasks:
- name: Dummy?
debug:
msg: "Some message"
48 changes: 48 additions & 0 deletions src/adcm_pytest_plugin/fixtures_data/provider/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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.
---
- type: provider
name: provider_name
version: 1.4
config:
- name: string
type: string
required: true
default: string
description: "That is description"
actions:
job:
script: provider_action.yaml
script_type: ansible
type: job
states:
available:
- created

- type: host
name: host_name
version: 1.0
description: "That is description"
config:
- name: string
type: string
required: true
default: string
actions:
switch_host_state:
type: job
script_type: ansible
script: dummy_action.yaml
states:
available:
- created
on_success: installed
21 changes: 21 additions & 0 deletions src/adcm_pytest_plugin/fixtures_data/provider/dummy_action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.
---
- name: Dummy action
hosts: all
connection: local
gather_facts: no

tasks:
- name: Dummy?
debug:
msg: "Some message"

0 comments on commit 26ba259

Please sign in to comment.