Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ def __init__(self, server_config=None, **kwargs):
'Ovirt',
'Rackspace',
'Vmware',
'Kubevirt',
),
),
'provider_friendly_name': entity_fields.StringField(),
Expand Down Expand Up @@ -1720,6 +1721,32 @@ def read(self, entity=None, attrs=None, ignore=None, params=None):
return super().read(entity, attrs, ignore, params)


class OCPVComputeResource(AbstractComputeResource):
"""A representation of a Kubevirt/OpenShift Virtualization Compute Resource entity."""

def __init__(self, server_config=None, **kwargs):
self._fields = {
'hostname': entity_fields.StringField(required=True),
'api_port': entity_fields.StringField(required=True),
'namespace': entity_fields.StringField(required=True),
'token': entity_fields.StringField(required=True),
'ca_cert': entity_fields.StringField(required=True),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this field is not required

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently if we don't pass this field, we get following error

Could not create the compute resource:
  SSL_connect returned=1 errno=0 state=error: certificate verify failed (self-signed certificate in certificate chain)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but that doesn't mean it's required by the API, which is what I was after.

If your OS trusts the CA, you don't need to pass ca_cert. In most cases it won't, so you have to pass it, but that doesn't make the field required.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I get you, so technically its not required, but for our tests we don't have OS trusts the CA, so it becomes required anyway and we can revisit this in future if we cover that case

}
super().__init__(server_config=server_config, **kwargs)
del self._fields['url']
self._fields['provider'].default = 'Kubevirt'
self._fields['provider'].required = True
self._fields['provider_friendly_name'].default = 'OpenShift Virtualization'

def read(self, entity=None, attrs=None, ignore=None, params=None):
"""Make sure, ``token`` is in the ignore list for read."""
if ignore is None:
ignore = set()
ignore.add('token')
ignore.add('ca_cert')
return super().read(entity, attrs, ignore, params)


class VMWareComputeResource(AbstractComputeResource):
"""A representation for compute resources with Vmware provider."""

Expand Down
2 changes: 2 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def test_init_succeeds(self):
# entities.OSDefaultTemplate, # see below
entities.OperatingSystem,
entities.Organization,
entities.OCPVComputeResource,
entities.OVirtComputeResource,
entities.PackageGroupContentViewFilter,
entities.PartitionTable,
Expand Down Expand Up @@ -1265,6 +1266,7 @@ def test_ignore_arg_v1(self):
for entity, ignored_attrs in (
(entities.AzureRMComputeResource, {'secret_key'}),
(entities.Errata, {'content_view_version', 'environment', 'repository'}),
(entities.OCPVComputeResource, {'token', 'ca_cert'}),
(entities.OVirtComputeResource, {'password'}),
(entities.SmartProxy, {'download_policy', 'http_proxy'}),
(entities.SmartClassParameters, {'hidden_value'}),
Expand Down