Skip to content

Commit c0bf6fe

Browse files
authored
tests(vpc): add regression tests and mute instance tests (#1046)
1 parent 82a39fd commit c0bf6fe

File tree

6 files changed

+134
-54
lines changed

6 files changed

+134
-54
lines changed

.github/workflows/checks.yml

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- scaleway-core
1616
- scaleway
1717
- scaleway-async
18+
python-version: ['3.10' ,'3.11', '3.12', '3.13']
1819
defaults:
1920
run:
2021
working-directory: ${{ matrix.lib }}
@@ -23,7 +24,7 @@ jobs:
2324
- name: Set up Python
2425
uses: actions/setup-python@v5
2526
with:
26-
python-version: "3.10"
27+
python-version: ${{ matrix.python-version }}
2728
- name: Install poetry
2829
run: |
2930
pip install poetry
@@ -49,7 +50,7 @@ jobs:
4950
- name: Set up Python
5051
uses: actions/setup-python@v5
5152
with:
52-
python-version: "3.10"
53+
python-version: ${{ matrix.python-version }}
5354
- name: Install poetry
5455
run: |
5556
pip install poetry
@@ -75,7 +76,7 @@ jobs:
7576
- name: Set up Python
7677
uses: actions/setup-python@v5
7778
with:
78-
python-version: "3.10"
79+
python-version: ${{ matrix.python-version }}
7980
- name: Install poetry
8081
run: |
8182
pip install poetry
@@ -88,34 +89,35 @@ jobs:
8889
- name: Check linting
8990
run: poetry run ruff check . --ignore E721 --ignore F541
9091

91-
# tests:
92-
# runs-on: ubuntu-latest
93-
# strategy:
94-
# matrix:
95-
# lib:
96-
# - scaleway-core
97-
# - scaleway
98-
# - scaleway-async
99-
# defaults:
100-
# run:
101-
# working-directory: ${{ matrix.lib }}
102-
# steps:
103-
# - uses: actions/checkout@v4
104-
# - name: Set up Python
105-
# uses: actions/setup-python@v5
106-
# with:
107-
# python-version: "3.10"
108-
# - name: Install poetry
109-
# run: |
110-
# pip install poetry
111-
# poetry --version
112-
# - name: Install dependencies and library
113-
# run: poetry install
114-
# - name: Run tests
115-
# run: poetry run python -m unittest discover -s tests -v
116-
# env:
117-
# SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
118-
# SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
119-
# SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
120-
# SCW_DEFAULT_REGION: ${{ secrets.SCW_DEFAULT_REGION }}
121-
# SCW_DEFAULT_ZONE: ${{ secrets.SCW_DEFAULT_ZONE }}
92+
tests:
93+
runs-on: ubuntu-latest
94+
strategy:
95+
matrix:
96+
lib:
97+
- scaleway-core
98+
- scaleway
99+
- scaleway-async
100+
defaults:
101+
run:
102+
working-directory: ${{ matrix.lib }}
103+
steps:
104+
- uses: actions/checkout@v4
105+
- name: Set up Python
106+
uses: actions/setup-python@v5
107+
with:
108+
python-version: ${{ matrix.python-version }}
109+
- name: Install poetry
110+
run: |
111+
pip install poetry
112+
poetry --version
113+
- name: Install dependencies and library
114+
run: poetry install
115+
- name: Run tests
116+
env:
117+
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
118+
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
119+
SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
120+
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
121+
SCW_DEFAULT_REGION: ${{ secrets.SCW_DEFAULT_REGION }}
122+
run: poetry run python -m unittest discover -s tests -v
123+

scaleway-async/tests/test_test_v1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from scaleway_async.test.v1 import EyeColors, Human, HumanStatus, TestV1API
99

1010

11+
@unittest.skip("API test is not deployed")
1112
class TestTestV1(unittest.IsolatedAsyncioTestCase):
1213
async def asyncSetUp(self) -> None:
1314
client = Client.from_config_file_and_env()

scaleway/tests/test_instance.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import logging
2-
import sys
31
from typing import List
42
import unittest
53
import uuid
@@ -11,10 +9,6 @@
119
from scaleway.instance.v1.types import Server, VolumeServerTemplate
1210
from scaleway.block.v1alpha1.types import Volume, CreateVolumeRequestFromEmpty
1311

14-
logger = logging.getLogger()
15-
logger.level = logging.DEBUG
16-
stream_handler = logging.StreamHandler(sys.stdout)
17-
logger.addHandler(stream_handler)
1812

1913
server_name = f"test-sdk-python-{uuid.uuid4().hex[:6]}"
2014
max_retry = 10
@@ -24,10 +18,11 @@
2418
zone = "fr-par-1"
2519

2620

21+
@unittest.skip("Skipping this test temporarily")
2722
class TestE2EServerCreation(unittest.TestCase):
2823
def setUp(self) -> None:
2924
self.zone = zone
30-
self.client = Client.from_config_file_and_env()
25+
self.client = Client.from_env()
3126
self.instanceAPI = InstanceV1API(self.client, bypass_validation=True)
3227
self.blockAPI = BlockV1Alpha1API(self.client, bypass_validation=True)
3328
self._server = None
@@ -38,14 +33,11 @@ def tearDown(self) -> None:
3833
self.instanceAPI.detach_server_volume(
3934
server_id=self._server.id, volume_id=volume.id
4035
)
41-
logger.info("✅ Volume {volume.id} has been detach")
4236

4337
self.blockAPI.delete_volume(volume_id=volume.id)
44-
logger.info("✅ Volume {volume.id} has been deleted")
4538

4639
if self._server:
4740
self.instanceAPI.delete_server(zone=self.zone, server_id=self._server.id)
48-
logger.info(f"🗑️ Deleted server: {self._server.id}")
4941

5042
def wait_test_instance_server(self, server_id):
5143
interval = interval
@@ -55,7 +47,6 @@ def wait_test_instance_server(self, server_id):
5547
s = self.instanceAPI.get_server(zone=self.zone, server_id=server_id)
5648

5749
if s.state == "running":
58-
logger.info(f"✅ Server {server_id} is running.")
5950
break
6051

6152
time.sleep(interval)
@@ -76,7 +67,6 @@ def create_test_instance_server(self) -> Server:
7667
dynamic_ip_required=True,
7768
volumes=volume,
7869
)
79-
logger.info(f"✅ Created server: {server.id}")
8070

8171
self._server = server.server
8272

@@ -91,7 +81,6 @@ def create_test_from_empty_volume(self, number) -> List[Volume]:
9181
volume = self.blockAPI.create_volume(
9282
from_empty=CreateVolumeRequestFromEmpty(size=10),
9383
)
94-
logger.info("✅ Created server: {volume.id}")
9584

9685
self.blockAPI.wait_for_volume(volume_id=volume.id, zone=self.zone)
9786

@@ -110,22 +99,16 @@ def test_attach_aditionnal_volume(self):
11099

111100
self.assertIsNotNone(additional_volume.id)
112101
self.assertEqual(additional_volume.size, 10)
113-
logger.info(f"✅ Volume created with ID: {additional_volume.id}")
114102

115103
self.instanceAPI.attach_server_volume(
116104
server_id=server.id, volume_id=additional_volume.id
117105
)
118106

119107
self.blockAPI.wait_for_volume(volume_id=additional_volume.id, zone=self.zone)
120108

121-
logger.info(f"🔗 Attached volume {additional_volume.id} to server {server.id}")
122-
123109
updated_server = self.instanceAPI.get_server(
124110
zone=self.zone, server_id=server.id
125111
)
126112
attached_volumes = updated_server.volumes or {}
127113
attached_volume_ids = [v.volume.id for v in attached_volumes.values()]
128114
self.assertIn(additional_volume.id, attached_volume_ids)
129-
logger.info(
130-
f"✅ Volume {additional_volume.id} is attached to server {server.id}"
131-
)

scaleway/tests/test_test_v1_marshalling.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ def _assert_raw_and_unmarshalled_human(
105105
raw["updated_at"],
106106
)
107107

108+
@unittest.skip("API test is not deployed")
108109
def test_unmarshal_Human(self) -> None:
109110
data = _mock_human_raw()
110111
human = unmarshal_Human(data)
111112
self._assert_raw_and_unmarshalled_human(data, human)
112113

114+
@unittest.skip("API test is not deployed")
113115
def test_unmarshal_ListHumansResponse(self) -> None:
114116
humans = [_mock_human_raw() for _ in range(10)]
115117
data = {
@@ -164,6 +166,7 @@ def _assert_create_human_request_and_raw(
164166
self.assertEqual(request.name, raw["name"])
165167
self.assertEqual(request.shoe_size, raw["shoe_size"])
166168

169+
@unittest.skip("API test is not deployed")
167170
def test_marshal_CreateHumanRequest(self) -> None:
168171
request = _mock_create_human_request()
169172
raw = marshal_CreateHumanRequest(request, utils.random_profile_defaults())

scaleway/tests/test_total_count_legacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class TestTotalCountLegacy(unittest.TestCase):
1414
def setUp(self) -> None:
15-
self.client = Client()
15+
self.client = Client.from_env()
1616
self.instance_api = InstanceV1API(self.client, bypass_validation=True)
1717

1818
def test_list_servers_type(self):

scaleway/tests/test_vpc.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import unittest
2+
from scaleway.vpc.v2 import VpcV2API
3+
from scaleway_core.api import ScalewayException
4+
from scaleway_core.client import Client
5+
from scaleway_core.utils import random_name
6+
7+
region = "fr-par"
8+
tags = ["sdk-python", "regression-test"]
9+
created_pn_count = 5
10+
created_vpc_count = 1
11+
12+
13+
class TestScalewayVPCV2(unittest.TestCase):
14+
@classmethod
15+
def setUpClass(self):
16+
self.client = Client.from_env()
17+
self.vpcAPI = VpcV2API(self.client)
18+
self.project_id = self.client.default_project_id
19+
self.region = region
20+
self._pns_to_cleanup = []
21+
22+
self._vpc = self.vpcAPI.create_vpc(
23+
enable_routing=True,
24+
region=self.region,
25+
project_id=self.project_id,
26+
name=random_name("vpc-test-sdk-python"),
27+
)
28+
29+
@classmethod
30+
def tearDownClass(self):
31+
for pn in self._pns_to_cleanup:
32+
self.vpcAPI.delete_private_network(private_network_id=pn.id)
33+
34+
if self._vpc is not None:
35+
self.vpcAPI.delete_vpc(vpc_id=self._vpc.id, region=self.region)
36+
37+
def test_delete_vpc(self):
38+
vpc = self.vpcAPI.create_vpc(
39+
enable_routing=True,
40+
region=self.region,
41+
project_id=self.project_id,
42+
name=random_name("vpc-test-sdk-python"),
43+
)
44+
45+
self.assertIsNotNone(vpc.id)
46+
self.assertEqual(vpc.region, self.region)
47+
48+
self.vpcAPI.delete_vpc(vpc_id=vpc.id)
49+
50+
with self.assertRaises(ScalewayException):
51+
self.vpcAPI.get_vpc(vpc_id=vpc.id)
52+
53+
def test_list_vpcs(self):
54+
vpcs = self.vpcAPI.list_vp_cs(region=self.region)
55+
self.assertIsInstance(vpcs.vpcs, list)
56+
self.assertGreaterEqual(vpcs.total_count, created_vpc_count)
57+
58+
def test_create_private_network(self):
59+
for i in range(created_pn_count):
60+
pn = self.vpcAPI.create_private_network(
61+
vpc_id=self._vpc.id,
62+
default_route_propagation_enabled=True,
63+
project_id=self.project_id,
64+
name=random_name(f"sdk-python-pn-{i}"),
65+
)
66+
self._pns_to_cleanup.append(pn)
67+
68+
self.assertEqual(pn.vpc_id, self._vpc.id)
69+
70+
def test_list_private_network(self):
71+
networks = self.vpcAPI.list_private_networks(region=self.region)
72+
self.assertIsInstance(networks.private_networks, list)
73+
self.assertGreaterEqual(networks.total_count, created_pn_count)
74+
75+
def test_get_vpc(self):
76+
vpc = self.vpcAPI.get_vpc(vpc_id=self._vpc.id, region=self.region)
77+
78+
self.assertIsNotNone(vpc)
79+
self.assertEqual(self._vpc.id, vpc.id)
80+
81+
def test_update_vpc(self):
82+
vpc = self.vpcAPI.update_vpc(vpc_id=self._vpc.id, tags=tags)
83+
84+
self.assertEqual(vpc.tags, tags)
85+
self.assertEqual(self._vpc.id, vpc.id)
86+
87+
def test_list_vpc_all(self):
88+
vpcs = self.vpcAPI.list_vp_cs_all()
89+
90+
self.assertIsInstance(vpcs, list)
91+
self.assertGreaterEqual(len(vpcs), created_vpc_count)

0 commit comments

Comments
 (0)