Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/csi 4868 remove default values from dataclass #674

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
28 changes: 13 additions & 15 deletions controllers/servers/host_definer/definition_manager/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,30 @@ def generate_request(self, host_definition_info):
node_name = host_definition_info.node_name
logger.info(messages.GENERATE_REQUEST_FOR_NODE.format(node_name))
node_info = self.resource_info_manager.get_node_info(node_name)
request = self._get_new_request(node_info.labels)
request = self._add_array_connectivity_info_to_request(
request, host_definition_info.secret_name, host_definition_info.secret_namespace, node_info.labels)
request = self._get_new_request(host_definition_info.secret_name,
host_definition_info.secret_namespace, node_info.labels)
if request:
request.node_id_from_host_definition = host_definition_info.node_id
request.node_id_from_csi_node = self._get_node_id_by_node(host_definition_info)
request.io_group = self._get_io_group_by_node(host_definition_info.node_name)
return request

def _get_new_request(self, labels):
request = DefineHostRequest()
def _get_new_request(self, secret_name, secret_namespace, labels):
connectivity_type_label_on_node = self._get_label_value(labels, common_settings.CONNECTIVITY_TYPE_LABEL)
request.prefix = utils.get_prefix()
request.connectivity_type_from_user = utils.get_connectivity_type_from_user(connectivity_type_label_on_node)
return request
prefix = utils.get_prefix()
connectivity_type_from_user = utils.get_connectivity_type_from_user(connectivity_type_label_on_node)
array_connection_info = self.secret_manager.get_array_connection_info(secret_name, secret_namespace, labels)

if array_connection_info:
return DefineHostRequest(
prefix=prefix, connectivity_type_from_user=connectivity_type_from_user,
array_connection_info=array_connection_info, node_id_from_host_definition='', node_id_from_csi_node='',
io_group='')
Comment on lines +40 to +41
Copy link
Contributor

Choose a reason for hiding this comment

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

if its ok to values to be empty so default value is better..

return None

def _get_label_value(self, labels, label):
return labels.get(label)

def _add_array_connectivity_info_to_request(self, request, secret_name, secret_namespace, labels):
request.array_connection_info = self.secret_manager.get_array_connection_info(
secret_name, secret_namespace, labels)
if request.array_connection_info:
return request
return None

def _get_node_id_by_node(self, host_definition_info):
try:
return NODES[host_definition_info.node_name].node_id
Expand Down
20 changes: 6 additions & 14 deletions controllers/servers/host_definer/resource_manager/resource_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ def get_csi_node_info(self, node_name):
k8s_csi_node = self.k8s_api.get_csi_node(node_name)
if k8s_csi_node:
return self.generate_csi_node_info(k8s_csi_node)
return CsiNodeInfo()
return CsiNodeInfo('', '')

def generate_csi_node_info(self, k8s_csi_node):
csi_node_info = CsiNodeInfo()
csi_node_info.name = k8s_csi_node.metadata.name
csi_node_info.node_id = self._get_node_id_from_k8s_csi_node(k8s_csi_node)
return csi_node_info
return CsiNodeInfo(name=k8s_csi_node.metadata.name, node_id=self._get_node_id_from_k8s_csi_node(k8s_csi_node))

def _get_node_id_from_k8s_csi_node(self, k8s_csi_node):
if k8s_csi_node.spec.drivers:
Expand All @@ -50,11 +47,9 @@ def get_storage_classes_info(self):
return storage_classes_info

def generate_storage_class_info(self, k8s_storage_class):
storage_class_info = StorageClassInfo()
storage_class_info.name = k8s_storage_class.metadata.name
storage_class_info.provisioner = k8s_storage_class.provisioner
storage_class_info.parameters = k8s_storage_class.parameters
return storage_class_info
return StorageClassInfo(
name=k8s_storage_class.metadata.name, provisioner=k8s_storage_class.provisioner,
parameters=k8s_storage_class.parameters)

def get_csi_pods_info(self):
pods_info = []
Expand All @@ -67,10 +62,7 @@ def get_csi_pods_info(self):
return pods_info

def _generate_pod_info(self, k8s_pod):
pod_info = PodInfo()
pod_info.name = k8s_pod.metadata.name
pod_info.node_name = k8s_pod.spec.node_name
return pod_info
return PodInfo(name=k8s_pod.metadata.name, node_name=k8s_pod.spec.node_name)

def generate_host_definition_info(self, k8s_host_definition):
host_definition_info = HostDefinitionInfo()
Expand Down
26 changes: 13 additions & 13 deletions controllers/servers/host_definer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

@dataclass
class DefineHostRequest:
prefix: str = ''
connectivity_type_from_user: str = ''
node_id_from_host_definition: str = ''
node_id_from_csi_node: str = ''
array_connection_info: ArrayConnectionInfo = ArrayConnectionInfo(array_addresses='', user='', password='')
io_group: str = ''
prefix: str
connectivity_type_from_user: str
array_connection_info: ArrayConnectionInfo
node_id_from_host_definition: str
node_id_from_csi_node: str
io_group: str


@dataclass
Expand Down Expand Up @@ -49,14 +49,14 @@ class HostDefinitionInfo:

@dataclass
class CsiNodeInfo:
name: str = ''
node_id: str = ''
name: str
node_id: str


@dataclass
class PodInfo:
name: str = ''
node_name: str = ''
name: str
node_name: str


@dataclass
Expand All @@ -67,9 +67,9 @@ class NodeInfo:

@dataclass
class StorageClassInfo:
name: str = ''
provisioner: str = ''
parameters: dict = field(default_factory=dict)
name: str
provisioner: str
parameters: dict


class ManagedNode:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ def get_array_connection_info():

def get_define_request(prefix='', connectivity_type='', node_id_from_host_definition=''):
return DefineHostRequest(
prefix, connectivity_type, node_id_from_host_definition, test_settings.FAKE_NODE_ID,
get_array_connection_info(),
test_settings.FAKE_STRING_IO_GROUP)
prefix, connectivity_type, get_array_connection_info(),
node_id_from_host_definition, test_settings.FAKE_NODE_ID, test_settings.FAKE_STRING_IO_GROUP)


def get_define_response(connectivity_type, ports):
Expand Down