Skip to content

Commit

Permalink
merge django-1.10 and django-1.11 branches
Browse files Browse the repository at this point in the history
  • Loading branch information
hipek8 committed Jun 12, 2024
2 parents a8b9c31 + d4d3ee8 commit d3772fb
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 42 deletions.
38 changes: 38 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
ralph (20240611.1) bionic; urgency=medium

* Test example changes
* Add workflow to build snapshot
* Run on push
* Add missing makefile target
* Test variables in Makefile
* Fix makefile
* Fix makefile
* Clean up changes. Snapshots should work now
* Add missing prefetches. Fix tests
* Adjust expected queries count in tests after modifications. Fix securityscan tests
* Adjust queries count in tests
* Fix flake
* Fix cluster factory
* Fix last test

-- Paweł Szulc <pawel.szulc@allegro.com> Tue, 11 Jun 2024 12:56:13 +0000

ralph (20240611.1) bionic; urgency=medium

* Test example changes
* Add workflow to build snapshot
* Run on push
* Add missing makefile target
* Test variables in Makefile
* Fix makefile
* Fix makefile
* Clean up changes. Snapshots should work now
* Add missing prefetches. Fix tests
* Adjust expected queries count in tests after modifications. Fix securityscan tests
* Adjust queries count in tests
* Fix flake
* Fix cluster factory
* Fix last test

-- Paweł Szulc <pawel.szulc@allegro.com> Tue, 11 Jun 2024 12:45:08 +0000

ralph (20240307.1) bionic; urgency=medium

[ Aleksander Więckowski ]
Expand Down
2 changes: 2 additions & 0 deletions src/ralph/assets/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class Meta(NetworkableObjectFilters.Meta):
*BaseObjectLicenceViewSet.select_related
),
),
"securityscan__tags",
"securityscan__vulnerabilities__tags",
"custom_fields",
"service_env__service__business_owners",
"service_env__service__technical_owners",
Expand Down
9 changes: 3 additions & 6 deletions src/ralph/assets/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,15 +954,12 @@ def setUp(self):
self.cloud_host.update_custom_field('test_cf', 'xyz')

def test_get_dc_hosts_list(self):
# create extra 60 DCHosts
dc_assets = DataCenterAssetFullFactory.create_batch(20)
VirtualServerFullFactory.create_batch(20, parent=dc_assets[0])
CloudHostFullFactory.create_batch(20, hypervisor=dc_assets[0])

url = reverse('dchost-list')
with self.assertNumQueries(28):
response = self.client.get(url + "?limit=100", format='json')

url = reverse('dchost-list') + "?limit=100"
with self.assertNumQueries(15):
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 63)

Expand Down
2 changes: 2 additions & 0 deletions src/ralph/back_office/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
OfficeInfrastructure,
Warehouse
)
from ralph.security.tests.factories import SecurityScanFactory

date_now = datetime.now().date()

Expand Down Expand Up @@ -57,6 +58,7 @@ class BackOfficeAssetFactory(DjangoModelFactory):
invoice_date = date_now - timedelta(days=15)
invoice_no = factory.Sequence(lambda n: 'Invoice number ' + str(n))
price = FuzzyDecimal(10, 300)
securityscan = factory.RelatedFactory(SecurityScanFactory, 'base_object')

class Meta:
model = BackOfficeAsset
Expand Down
6 changes: 4 additions & 2 deletions src/ralph/back_office/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def setUp(self):
self.bo_asset.save()

def test_get_back_office_assets_list(self):
url = reverse('backofficeasset-list')
response = self.client.get(url, format='json')
BackOfficeAssetFactory.create_batch(100)
url = reverse('backofficeasset-list') + "?limit=100"
with self.assertNumQueries(14):
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.data['count'], BackOfficeAsset.objects.count()
Expand Down
7 changes: 0 additions & 7 deletions src/ralph/data_center/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
ServerRoom,
VIP
)
from ralph.security.models import SecurityScan


class DataCenterAssetFilterSet(NetworkableObjectFilters):
Expand Down Expand Up @@ -69,12 +68,6 @@ class DataCenterAssetViewSet(BaseObjectViewSetMixin, RalphAPIViewSet):
'ethernet_set',
queryset=Ethernet.objects.select_related('ipaddress')
),
Prefetch(
'securityscan',
queryset=SecurityScan.objects.prefetch_related(
'vulnerabilities', 'tags'
)
),
'fibrechannelcard_set',
'processor_set',
'disk_set',
Expand Down
6 changes: 3 additions & 3 deletions src/ralph/data_center/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ class Meta:

class ClusterFactory(DjangoModelFactory):

name = factory.Iterator(
['Databases', 'Applications', 'Switch', 'Load balancer']
)
name = factory.Sequence(lambda n: f"Cluster {n}")
type = factory.SubFactory(ClusterTypeFactory)
configuration_path = factory.SubFactory(ConfigurationClassFactory)
service_env = factory.SubFactory(ServiceEnvironmentFactory)
Expand Down Expand Up @@ -213,6 +211,8 @@ class DataCenterAssetFullFactory(DataCenterAssetFactory):
)
securityscan = factory.RelatedFactory(SecurityScanFactory, factory_related_name='base_object')

securityscan = factory.RelatedFactory(SecurityScanFactory, 'base_object')

@factory.post_generation
def post_tags(self, create, extracted, **kwargs):
self.tags.add('abc, cde', 'xyz')
Expand Down
15 changes: 8 additions & 7 deletions src/ralph/data_center/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def setUp(self):
self.dc_asset_2 = DataCenterAssetFullFactory(rack=self.rack)

def test_get_data_center_assets_list(self):
url = reverse('datacenterasset-list')
DataCenterAssetFullFactory.create_batch(18, rack=self.rack)
with self.assertNumQueries(18):
DataCenterAssetFullFactory.create_batch(100)
url = reverse('datacenterasset-list') + "?limit=100"
with self.assertNumQueries(20):
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
Expand Down Expand Up @@ -552,18 +552,19 @@ def test_create_cluster_without_hostname_or_name(self):
})

def test_list_cluster(self):
url = reverse('cluster-list')
with self.assertNumQueries(12):
ClusterFactory.create_batch(20)
url = reverse('cluster-list') + "?limit=100"
with self.assertNumQueries(13):
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data['results']), 2)
self.assertEqual(len(response.data['results']), 22)
for item in response.data['results']:
if item['id'] == self.cluster_1.id:
self.assertEqual(len(item['base_objects']), 2)

def test_get_cluster_details(self):
url = reverse('cluster-detail', args=(self.cluster_1.id,))
with self.assertNumQueries(11):
with self.assertNumQueries(12):
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['name'], self.cluster_1.name)
Expand Down
4 changes: 4 additions & 0 deletions src/ralph/data_center/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def setUp(self):
rack__name='Rack #1',
rack__server_room__name='SR1',
rack__server_room__data_center__name='DC1',
securityscan=None,
)

def test_listing_show_ok_when_scan_succeed_and_no_vulnerabilities(
Expand Down Expand Up @@ -219,6 +220,7 @@ def setUp(self):
rack__name='Rack #1',
rack__server_room__name='SR1',
rack__server_room__data_center__name='DC1',
securityscan=None,
)
self.scan_no_vuls = SecurityScanFactory(
base_object=self.asset_no_vuls.baseobject_ptr, vulnerabilities=[],
Expand All @@ -232,6 +234,7 @@ def setUp(self):
rack__name='Rack #1',
rack__server_room__name='SR1',
rack__server_room__data_center__name='DC1',
securityscan=None,
)
self.scan_with_vuls2 = SecurityScanFactory(
base_object=self.asset_with_today_vul.baseobject_ptr,
Expand All @@ -246,6 +249,7 @@ def setUp(self):
rack__name='Rack #1',
rack__server_room__name='SR1',
rack__server_room__data_center__name='DC1',
securityscan=None,
)
self.scan_with_vuls2 = SecurityScanFactory(
base_object=self.asset_vuls2.baseobject_ptr,
Expand Down
14 changes: 4 additions & 10 deletions src/ralph/virtual/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from ralph.data_center.models import DCHost
from ralph.lib.api.exceptions import Conflict
from ralph.security.api import SecurityScanSerializer
from ralph.security.models import SecurityScan
from ralph.virtual.admin import VirtualServerAdmin
from ralph.virtual.models import (
CloudFlavor,
Expand Down Expand Up @@ -244,9 +243,10 @@ class CloudHostViewSet(BaseObjectViewSetMixin, RalphAPIViewSet):
]
prefetch_related = base_object_descendant_prefetch_related + [
'tags', 'cloudflavor__virtualcomponent_set__model', 'licences',
'securityscan__vulnerabilities__tags',
'securityscan__tags',
'ethernet_set__ipaddress',
Prefetch(
'ethernet_set',
queryset=Ethernet.objects.select_related('ipaddress')
),
]

filter_fields = [
Expand Down Expand Up @@ -292,12 +292,6 @@ class VirtualServerViewSet(BaseObjectViewSetMixin, RalphAPIViewSet):
'ethernet_set',
queryset=Ethernet.objects.select_related('ipaddress')
),
Prefetch(
'securityscan',
queryset=SecurityScan.objects.prefetch_related(
'vulnerabilities', 'tags'
)
),
# TODO: clusters
]
filter_fields = [
Expand Down
4 changes: 3 additions & 1 deletion src/ralph/virtual/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class Meta:

class CloudHostFullFactory(CloudHostFactory):
hypervisor = factory.SubFactory(DataCenterAssetFactory)
securityscan = factory.RelatedFactory(SecurityScanFactory, factory_related_name='base_object')
securityscan = factory.RelatedFactory(SecurityScanFactory, 'base_object')


@factory.post_generation
def post_tags(self, create, extracted, **kwargs):
Expand Down Expand Up @@ -143,6 +144,7 @@ class VirtualServerFullFactory(VirtualServerFactory):
proc2 = factory.RelatedFactory(ProcessorFactory, 'base_object')
disk1 = factory.RelatedFactory(DiskFactory, 'base_object')
disk2 = factory.RelatedFactory(DiskFactory, 'base_object')
securityscan = factory.RelatedFactory(SecurityScanFactory, 'base_object')

@factory.post_generation
def post_tags(self, create, extracted, **kwargs):
Expand Down
11 changes: 6 additions & 5 deletions src/ralph/virtual/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def test_get_list(self, field):

def test_get_cloudhost_list(self):
CloudHostFullFactory.create_batch(100)
url = reverse('cloudhost-list')
url = reverse('cloudhost-list') + "?limit=100"
with self.assertNumQueries(15):
response = self.client.get(url + "?limit=100", format='json')
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data['results']), 100)
self.assertEqual(response.data['count'], 102)
Expand Down Expand Up @@ -452,11 +452,12 @@ def setUp(self):
)

def test_get_virtual_server_list(self):
url = reverse('virtualserver-list')
with self.assertNumQueries(13):
VirtualServerFullFactory.create_batch(20)
url = reverse('virtualserver-list') + "?limit=100"
with self.assertNumQueries(16):
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 2)
self.assertEqual(response.data['count'], 22)

def test_get_virtual_server_details(self):
url = reverse('virtualserver-detail', args=(self.virtual_server.id,))
Expand Down
2 changes: 1 addition & 1 deletion src/ralph/virtual/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_cleanup_security_scan_transition(self):

class VirtualServerTestCase(RalphTestCase, NetworkableBaseObjectTestMixin):
def setUp(self):
self.vs = VirtualServerFullFactory()
self.vs = VirtualServerFullFactory(securityscan=None)
self.custom_field_str = CustomField.objects.create(
name='test str', type=CustomFieldTypes.STRING, default_value='xyz'
)
Expand Down

0 comments on commit d3772fb

Please sign in to comment.