Skip to content

Commit

Permalink
Revert wait_for_delete_group method, use default sec_group for tests (#…
Browse files Browse the repository at this point in the history
…214)

Revert wait_for_delete_group method, use default sec_group for tests

In this PR wait_for_delete_group method was reverted, also default securitu group was used for tests, tests were fixed.

Reviewed-by: None <None>
Reviewed-by: Polina Gubina <None>
Reviewed-by: Anton Sidelnikov <None>
Reviewed-by: Artem Goncharov <[email protected]>
  • Loading branch information
irina-pereiaslavskaia authored Jul 15, 2021
1 parent 026f964 commit e3b853c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 45 deletions.
12 changes: 1 addition & 11 deletions otcextensions/sdk/auto_scaling/v1/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,7 @@ def wait_for_delete_group(self, group, interval=2, wait=60):
to status failed to occur in wait seconds.
"""
group = self._get_resource(_group.Group, group)
for count in utils.iterate_timeout(
timeout=wait,
message="Timeout waiting for group to delete",
wait=interval
):
try:
group = self._get(_group.Group, group)
if not group:
return
except exceptions.NotFoundException:
return
return resource.wait_for_delete(self, group, interval, wait)

# ======== Configurations ========
def configs(self, **query):
Expand Down
18 changes: 0 additions & 18 deletions otcextensions/tests/functional/sdk/auto_scaling/v1/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class BaseASTest(base.BaseFunctionalTest):
NETWORK_NAME = "test-as-network-" + UUID
SUBNET_NAME = "test-as-subnet-" + UUID
ROUTER_NAME = "test-as-router-" + UUID
SG_NAME = "test-as-sec-group-" + UUID
KP_NAME = "test-as-kp-" + UUID
IP_VERSION = 4
CIDR = "192.168.0.0/16"
Expand All @@ -43,16 +42,6 @@ def _delete_keypair(self, key_pair):
keypair=key_pair
)

def _create_sec_group(self):
return self.conn.network.create_security_group(
name=self.SG_NAME
)

def _delete_sec_group(self, sec_group):
return self.conn.network.delete_security_group(
security_group=sec_group
)

def _create_network(self):
return self.conn.network.create_network(
name=self.NETWORK_NAME
Expand Down Expand Up @@ -97,13 +86,11 @@ def _delete_router(self, router, subnet_id):

def create_test_infra(self):
key_pair = self._create_keypair()
sec_group = self._create_sec_group()
network = self._create_network()
subnet = self._create_subnet(network.id)
router = self._create_router(subnet.id)
return {
"key_pair_id": key_pair.id,
"sec_group_id": sec_group.id,
"network_id": network.id,
"subnet_id": subnet.id,
"router_id": router.id
Expand All @@ -113,18 +100,13 @@ def delete_test_infra(self, infra: dict):
router = self.conn.network.get_router(infra.get("router_id"))
subnet = self.conn.network.get_subnet(infra.get("subnet_id"))
network = self.conn.network.get_network(infra.get("network_id"))
sec_group = self.conn.network.get_security_group(
infra.get("sec_group_id")
)
key_pair = self.conn.compute.get_keypair(infra.get("key_pair_id"))
if router:
self._delete_router(router, subnet.id)
if subnet:
self._delete_subnet(subnet)
if network:
self._delete_network(network)
if sec_group:
self._delete_sec_group(sec_group)
if key_pair:
self._delete_keypair(key_pair)

Expand Down
14 changes: 11 additions & 3 deletions otcextensions/tests/functional/sdk/auto_scaling/v1/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def _get_image_id(self):
if image:
return image.id

def _get_default_sec_group(self):
sec_group = self.conn.network.find_security_group(
name_or_id="default"
)
if sec_group:
return sec_group.id

def _create_as_config(self, image_id, sec_group_id):
config_attrs = {
"name": self.AS_CONFIG_NAME,
Expand Down Expand Up @@ -144,11 +151,12 @@ def _delete_as_group(self, as_group, timeout, force_delete=False):
group=as_group,
force_delete=force_delete
)
return self.conn.auto_scaling.wait_for_delete_group(
self.conn.auto_scaling.wait_for_delete_group(
group=as_group,
interval=5,
wait=timeout
)
return self.conn.auto_scaling.find_group(name_or_id=self.AS_GROUP_NAME)

def _deinitialize_as_group(self):
timeout = int(os.environ.get('OS_TEST_TIMEOUT'))
Expand All @@ -171,7 +179,7 @@ def test_01_create_as_group(self):
def test_02_create_as_group_with_instance(self):
timeout = int(os.environ.get('OS_TEST_TIMEOUT'))
self.as_config = self._create_as_config(self._get_image_id(),
self.infra.get("sec_group_id"))
self._get_default_sec_group())
self.as_group = self._create_as_group(
router_id=self.infra.get("router_id"),
network_id=self.infra.get("network_id"),
Expand All @@ -187,7 +195,7 @@ def test_02_create_as_group_with_instance(self):
def test_03_simple_delete_as_group(self):
timeout = 2 * int(os.environ.get('OS_TEST_TIMEOUT'))
self.as_config = self._create_as_config(self._get_image_id(),
self.infra.get("sec_group_id"))
self._get_default_sec_group())
self.as_group = self._create_as_group(
router_id=self.infra.get("router_id"),
network_id=self.infra.get("network_id"),
Expand Down
33 changes: 20 additions & 13 deletions otcextensions/tests/functional/sdk/auto_scaling/v1/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,32 @@ class TestInstance(base.BaseASTest):
DISK_VOL_TYPE = "SATA"
DISK_TYPE = "SYS"

def setUp(self):
super(TestInstance, self).setUp()
self._initialize_as_group_with_instance()

def tearDown(self):
try:
self._deinitialize_as_group_with_instance()
except exceptions.SDKException as e:
_logger.warning('Got exception during clearing resources %s'
% e.message)
super(TestInstance, self).tearDown()

def _get_image_id(self):
image = self.conn.compute.find_image(
name_or_id=self.IMAGE_NAME
)
if image:
return image.id

def _get_default_sec_group(self):
sec_group = self.conn.network.find_security_group(
name_or_id="default"
)
if sec_group:
return sec_group.id

def _create_as_config(self, image_id, sec_group_id):
config_attrs = {
"name": self.AS_CONFIG_NAME,
Expand Down Expand Up @@ -117,7 +136,7 @@ def _delete_instance(self, instance):

def _initialize_as_group_with_instance(self):
self.as_config = self._create_as_config(
self._get_image_id(), self.infra.get("sec_group_id")
self._get_image_id(), self._get_default_sec_group()
)
self.as_group = self._create_as_group(
self.as_config.id, self.infra.get("router_id"),
Expand All @@ -135,18 +154,6 @@ def _deinitialize_as_group_with_instance(self):
if self.as_config:
self._delete_as_config(self.as_config)

def setUp(self):
super(TestInstance, self).setUp()
self._initialize_as_group_with_instance()

def tearDown(self):
try:
self._deinitialize_as_group_with_instance()
except exceptions.SDKException as e:
_logger.warning('Got exception during clearing resources %s'
% e.message)
super(TestInstance, self).tearDown()

def test_find_instance_by_id(self):
result = self.conn.auto_scaling.find_instance(
name_or_id=self.as_instance.id,
Expand Down

0 comments on commit e3b853c

Please sign in to comment.