Skip to content

Commit

Permalink
fix: fixes resolver and resource models to work with apply
Browse files Browse the repository at this point in the history
This commit contains miscellaneous bug fixes in order make the apply
command work properly for different resources.
  • Loading branch information
smrutisenapati authored and pallabpain committed Sep 4, 2024
1 parent af90e83 commit 8279b77
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 90 deletions.
5 changes: 0 additions & 5 deletions riocli/apply/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,8 @@ def _resolve_dependency(self, dependent_key, dependency):
self._add_remote_object_to_resolve_tree(
dependent_key, obj_guid, dependency, obj)

<<<<<<< HEAD
if (name_or_guid == obj_name) and (
'version' in dependency and obj['packageVersion'] == dependency.get('version')):
=======
if (name_or_guid == obj_name) and ('version' in dependency and
obj.metadata.version == dependency.get('version')):
>>>>>>> 52515c9 (feat(deployment): uses v2 deployments APIs)
self._add_remote_object_to_resolve_tree(
dependent_key, obj_guid, dependency, obj)

Expand Down
2 changes: 1 addition & 1 deletion riocli/apply/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _find_functors(self, kind):
"network": lambda name, obj_list, network_type: filter(
lambda x: name == x.metadata.name and network_type == x.spec.type, obj_list),
"deployment": lambda name, obj_list: filter(
lambda x: name == x.metadata.name, obj_list),
lambda x: name == x.metadata.name and not x.metadata.get('deletedAt'), obj_list),
"disk": lambda name, obj_list: filter(
lambda x: name == x.metadata.name, obj_list),
"device": self._generate_find_guid_functor(),
Expand Down
4 changes: 2 additions & 2 deletions riocli/deployment/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from riocli.utils.spinner import DummySpinner as Spinner

from riocli.constants import Colors
from riocli.deployment.util import name_to_guid, select_details
from riocli.deployment.util import select_details
from riocli.utils.execute import run_on_cloud


Expand All @@ -39,7 +39,7 @@
help='Name of a executable in the component')
@click.argument('deployment-name', type=str)
@click.argument('command', nargs=-1)
@name_to_guid
# @name_to_guid
def execute_command(
component_name: str,
exec_name: str,
Expand Down
60 changes: 0 additions & 60 deletions riocli/deployment/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@
# limitations under the License.
import functools
import re
import typing
from typing import List

import click

from riocli.config import new_client
from riocli.constants import Colors
from riocli.deployment.model import Deployment
from riocli.utils import tabulate_data
from riocli.utils.selector import show_selection
Expand All @@ -41,56 +37,6 @@
]


def name_to_guid(f: typing.Callable) -> typing.Callable:
@functools.wraps(f)
def decorated(**kwargs: typing.Any) -> None:
try:
client = new_client()
except Exception as e:
click.secho(str(e), fg=Colors.RED)
raise SystemExit(1) from e

name = kwargs.pop('deployment_name')
guid = None

if name.startswith('dep-'):
guid = name
name = None

try:
if name is None:
name = get_deployment_name(client, guid)

if guid is None:
guid = find_deployment_guid(client, name)
except Exception as e:
click.secho(str(e), fg=Colors.RED)
raise SystemExit(1) from e

kwargs['deployment_name'] = name
kwargs['deployment_guid'] = guid
f(**kwargs)

return decorated


def get_deployment_name(client: Client, guid: str) -> str:
deployment = client.get_deployment(guid)
return deployment.name


def find_deployment_guid(client: Client, name: str) -> str:
find_func = functools.partial(client.get_all_deployments,
phases=[DeploymentPhaseConstants.SUCCEEDED,
DeploymentPhaseConstants.PROVISIONING])
deployments = find_func()
for deployment in deployments:
if deployment.name == name:
return deployment.deploymentId

raise DeploymentNotFound()


def select_details(deployment_guid, component_name=None, exec_name=None) -> (str, str, str):
client = new_client()
deployment = client.get_deployment(deployment_guid)
Expand Down Expand Up @@ -126,12 +72,6 @@ def select_details(deployment_guid, component_name=None, exec_name=None) -> (str
return selected_component.componentID, exec_meta.id, pod_name


class DeploymentNotFound(Exception):
def __init__(self, message='deployment not found!'):
self.message = message
super().__init__(self.message)


def fetch_deployments(
client: Client,
deployment_name_or_regex: str,
Expand Down
7 changes: 2 additions & 5 deletions riocli/disk/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ def __init__(self, *args, **kwargs):
self.update(*args, **kwargs)

def find_object(self, client: Client) -> typing.Any:
_, disk = self.rc.find_depends({
guid, disk = self.rc.find_depends({
'kind': 'disk',
'nameOrGUID': self.metadata.name
})

if not disk:
return False

return disk
return disk if guid else False

def create_object(self, client: Client, **kwargs) -> typing.Any:
v2_client = new_v2_client()
Expand Down
12 changes: 3 additions & 9 deletions riocli/network/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@ def __init__(self, *args, **kwargs):
self.update(*args, **kwargs)

def find_object(self, client: Client) -> bool:
try:
network, obj = self.rc.find_depends({"kind": self.kind.lower(),
"nameOrGUID": self.metadata.name}, self.spec.type)
if not network:
return False

return obj
except NetworkNotFound:
return False
network, obj = self.rc.find_depends({"kind": self.kind.lower(),
"nameOrGUID": self.metadata.name}, self.spec.type)
return obj if network else False

def create_object(self, client: Client, **kwargs) -> typing.Any:
client = new_v2_client()
Expand Down
5 changes: 1 addition & 4 deletions riocli/package/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ def __init__(self, *args, **kwargs):
def find_object(self, client: Client):
guid, obj = self.rc.find_depends({"kind": self.kind.lower(), "nameOrGUID": self.metadata.name},
self.metadata.version)
if not guid:
return False

return obj
return obj if guid else False

def create_object(self, client: Client, **kwargs) -> typing.Any:
v2_client = new_v2_client()
Expand Down
7 changes: 3 additions & 4 deletions riocli/v2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from riocli.constants import Colors
from riocli.v2client.enums import DeploymentPhaseConstants, DiskStatusConstants
from riocli.v2client.error import (RetriesExhausted, DeploymentNotRunning, ImagePullError,
NetworkNotFound)
NetworkNotFound, DeploymentNotFound)


def handle_server_errors(response: requests.Response):
Expand Down Expand Up @@ -880,7 +880,7 @@ def get_network(
data = json.loads(response.text)

if response.status_code == http.HTTPStatus.NOT_FOUND:
raise NetworkNotFound()
raise NetworkNotFound("network: {} not found".format(name))

if not response.ok:
err_msg = data.get('error')
Expand Down Expand Up @@ -956,7 +956,6 @@ def list_deployments(

params = {
"continue": 0,
"limit": 100,
}
params.update(query or {})
result = []
Expand Down Expand Up @@ -1010,7 +1009,7 @@ def get_deployment(
data = json.loads(response.text)

if response.status_code == http.HTTPStatus.NOT_FOUND:
raise Exception("deployment: {} not found".format(name))
raise DeploymentNotFound("deployment: {} not found".format(name))

if not response.ok:
err_msg = data.get('error')
Expand Down

0 comments on commit 8279b77

Please sign in to comment.