Skip to content

Commit 0801794

Browse files
committed
Fixing lint issues
1 parent 183c2e1 commit 0801794

4 files changed

Lines changed: 67 additions & 69 deletions

File tree

requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ inflection
1313
miq-version>=0.1.6
1414
oauth2client
1515
ovirt-engine-sdk-python~=4.3
16-
#openshift==0.3.4
1716
openshift==0.8.8
1817
packaging
1918
pyvmomi>=6.5.0.2017.5.post1
@@ -32,7 +31,6 @@ six
3231
tzlocal
3332
vspk==5.3.2
3433
wait_for
35-
#websocket_client
3634
websocket_client==0.56.0
3735

3836
# suds jurko supports python3, suds is only used on python2

wrapanapi/entities/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313

1414
__all__ = [
1515
'Template', 'TemplateMixin', 'Vm', 'VmState', 'VmMixin', 'Instance',
16-
'PhysicalContainer', 'Server', 'ServerState', 'Stack', 'StackMixin'
16+
'PhysicalContainer', 'Server', 'ServerState', 'Stack', 'StackMixin',
17+
'Project', 'ProjectMixin'
1718
]

wrapanapi/entities/project.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
22
wrapanapi.entities.project
33
4-
Methods/classes pertaining to performing actions on a template
4+
Methods/classes pertaining to performing actions on a project
55
"""
66
import six
77

8-
from abc import ABCMeta, abstractmethod, abstractproperty
8+
from abc import ABCMeta, abstractmethod
99

1010
from wrapanapi.entities.base import Entity, EntityMixin
1111
from wrapanapi.exceptions import MultipleItemsError, NotFoundError
@@ -15,7 +15,7 @@ class Project(six.with_metaclass(ABCMeta, Entity)):
1515
"""
1616
Represents a project on a system
1717
"""
18-
@abstractproperty
18+
@abstractmethod
1919
def get_quota(self):
2020
"""
2121
Deploy a VM/instance with name 'vm_name' using this template
@@ -31,30 +31,30 @@ class ProjectMixin(six.with_metaclass(ABCMeta, EntityMixin)):
3131
@abstractmethod
3232
def get_project(self, name, **kwargs):
3333
"""
34-
Get template from system with name 'name'
34+
Get project from system with name 'name'
3535
3636
This should return only ONE matching entity. If multiple entities match
3737
the criteria, a MultipleItemsError should be raised
3838
3939
Returns:
40-
wrapanapi.entities.Template if it exists
40+
wrapanapi.entities.Project if it exists
4141
Raises:
4242
wrapanapi.exceptions.MultipleItemsError if multiple matches are found
4343
"""
4444

4545
@abstractmethod
4646
def create_project(self, name, **kwargs):
4747
"""
48-
Create template on system with name 'name'
48+
Create project on system with name 'name'
4949
5050
Returns:
51-
wrapanapi.entities.Template for newly created templated
51+
wrapanapi.entities.Project for newly created project
5252
"""
5353

5454
@abstractmethod
5555
def list_project(self, **kwargs):
5656
"""
57-
List templates on system
57+
List projects on system
5858
5959
Returns:
6060
list of wrapanapi.entities.Template
@@ -63,19 +63,19 @@ def list_project(self, **kwargs):
6363
@abstractmethod
6464
def find_projects(self, name, **kwargs):
6565
"""
66-
Find templates on system based on name or other filters in kwargs
66+
Find project on system based on name or other filters in kwargs
6767
6868
Should return an empty list if no matches were found
6969
7070
Returns:
71-
list of wrapanapi.entities.Template for matches found
71+
list of wrapanapi.entities.Project for matches found
7272
"""
7373

7474
def does_project_exist(self, name):
7575
"""
76-
Checks if a template with 'name' exists on the system
76+
Checks if a project with 'name' exists on the system
7777
78-
If multiple templates with the same name exists, this still returns 'True'
78+
If multiple projects with the same name exists, this still returns 'True'
7979
"""
8080
try:
8181
return bool(self.get_project(name))

wrapanapi/systems/openshift.py

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import copy
44
import json
5+
import re
56
import string
67
import yaml
78
from collections import Iterable
@@ -18,8 +19,7 @@
1819
from openshift import client as ociclient
1920
from wait_for import TimedOutError, wait_for
2021

21-
from wrapanapi.entities import (Template, Vm, VmMixin, VmState, ProjectMixin,
22-
Project)
22+
from wrapanapi.entities import (Template, Vm, VmMixin, VmState, ProjectMixin, Project)
2323
from wrapanapi.systems.base import System
2424

2525

@@ -88,23 +88,31 @@ def wrap(*args, **kwargs):
8888
return wrap
8989

9090

91-
class Project(Project):
91+
class RHOpenShiftProject(Project, Vm):
9292

9393
"""
9494
We are assuming that a Project is a VM for purposes of simplicity for CFME-QE
9595
9696
"""
9797

98+
state_map = {
99+
'Pending': VmState.PENDING,
100+
'Running': VmState.RUNNING,
101+
'Succeeded': VmState.SUCCEEDED,
102+
'Failed': VmState.FAILED,
103+
'Unknown': VmState.UNKNOWN
104+
}
105+
98106
def __init__(self, system, raw=None, **kwargs):
99107
"""
100-
Construct a VMWareVirtualMachine instance
108+
Construct a RHOpenShiftProject instance
101109
102110
Args:
103-
system: instance of VMWareSystem
104-
raw: pyVmomi.vim.VirtualMachine object
105-
name: name of VM
111+
system: instance of OpenShiftSystem
112+
raw: openshift.dynamic.client.ResourceField
113+
name: name of Project
106114
"""
107-
super(Project, self).__init__(system, raw, **kwargs)
115+
super(RHOpenShiftProject, self).__init__(system, raw, **kwargs)
108116
self._name = raw.metadata.name if raw else kwargs.get('name')
109117
if not self._name:
110118
raise ValueError("missing required kwarg 'name'")
@@ -127,7 +135,6 @@ def _does_project_exist(self):
127135
else:
128136
return False
129137

130-
@property
131138
def get_quota(self):
132139
return self.system.ocp_client.resources.get(api_version='v1', kind='ResourceQuota').get(
133140
namespace=self.name)
@@ -151,7 +158,18 @@ def uuid(self):
151158
def ip(self):
152159
raise NotImplementedError
153160

161+
@property
162+
def creation_time(self):
163+
"""
164+
Detect the project creation time
165+
166+
"""
167+
raise NotImplementedError
168+
154169
def start(self):
170+
"""
171+
Start the CFME pods
172+
"""
155173
self.logger.info("starting vm/project %s", self.name)
156174
if self._does_project_exist:
157175
for pod in self.system.get_required_pods(self.name):
@@ -160,11 +178,8 @@ def start(self):
160178
raise ValueError("Project with name {n} doesn't exist".format(n=self.name))
161179

162180
def stop(self):
163-
"""Stops a vm.
164-
165-
Args:
166-
vm_name: name of the vm to be stopped
167-
Returns: whether vm action has been initiated properly
181+
"""
182+
Stop the CFME pods
168183
"""
169184
self.logger.info("stopping vm/project %s", self.name)
170185
if self._does_project_exist:
@@ -187,7 +202,7 @@ def cleanup(self):
187202
return self.delete()
188203

189204

190-
class Pod(Vm):
205+
class RHOpenShiftPod(Vm):
191206
state_map = {
192207
'Pending': VmState.PENDING,
193208
'Running': VmState.RUNNING,
@@ -198,14 +213,14 @@ class Pod(Vm):
198213

199214
def __init__(self, system, raw=None, **kwargs):
200215
"""
201-
Construct a VMWareVirtualMachine instance
216+
Construct a RHOpenShiftPod instance
202217
203218
Args:
204-
system: instance of VMWareSystem
205-
raw: pyVmomi.vim.VirtualMachine object
206-
name: name of VM
219+
system: instance of OpenShiftSystem
220+
raw: openshift.dynamic.client.ResourceField
221+
name: name of Pod
207222
"""
208-
super(Pod, self).__init__(system, raw, **kwargs)
223+
super(RHOpenShiftPod, self).__init__(system, raw, **kwargs)
209224
self._name = raw.metadata.name if raw else kwargs.get('name')
210225
self._namespace = raw.metadata.namespace if raw else kwargs.get('namespace')
211226
if not self._name:
@@ -233,16 +248,15 @@ def namespace(self):
233248

234249
@property
235250
def ip(self):
236-
# TODO JUWATTS
237-
# ipv4_re = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
251+
ipv4_re = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
238252
self.refresh()
239253
try:
240-
return self.raw.status.podIP
254+
ip_address=self.raw.status.podIP
241255
if not re.match(ipv4_re, ip_address) or ip_address == '127.0.0.1':
242256
ip_address = None
243257
return ip_address
244258
except (AttributeError):
245-
# AttributeError: vm doesn't have an ip address yet
259+
# AttributeError: pod doesn't have an ip address yet
246260
return None
247261

248262
def _get_state(self):
@@ -270,12 +284,7 @@ def cleanup(self):
270284

271285
@property
272286
def creation_time(self):
273-
"""Detect the vm_creation_time either via uptime if non-zero, or by last boot time
274-
275-
The API provides no sensible way to actually get this value. The only way in which
276-
vcenter API MAY have this is by filtering through events
277-
278-
Return tz-naive datetime object
287+
"""Detect the pods creation time
279288
"""
280289
raise NotImplementedError
281290

@@ -284,12 +293,12 @@ class OpenShiftTemplate(Template):
284293

285294
def __init__(self, system, raw=None, **kwargs):
286295
"""
287-
Construct a VMWareVirtualMachine instance
296+
Construct a OpenShiftTemplate instance
288297
289298
Args:
290-
system: instance of VMWareSystem
291-
raw: pyVmomi.vim.VirtualMachine object
292-
name: name of VM
299+
system: instance of OpenShiftSystem
300+
raw: openshift.dynamic.client.ResourceField
301+
name: name of Template
293302
"""
294303
super(OpenShiftTemplate, self).__init__(system, raw, **kwargs)
295304
self._name = raw.metadata.name if raw else kwargs.get('name')
@@ -686,19 +695,6 @@ def _k8s_client_connect(self):
686695
# Create a ApiClient with our config
687696
return kubeclient.ApiClient(k8_configuration)
688697

689-
# def _connect(self):
690-
#
691-
# self.dyn_client = DynamicClient(self.k8s_client)
692-
693-
# self.ociclient = ociclient
694-
# self.kclient = kubeclient
695-
# self.oapi_client = ociclient.ApiClient(config=config)
696-
# self.kapi_client = kubeclient.ApiClient(config=config)
697-
# self.o_api = ociclient.OapiApi(api_client=self.oapi_client)
698-
# self.k_api = kubeclient.CoreV1Api(api_client=self.kapi_client)
699-
# self.security_api = self.ociclient.SecurityOpenshiftIoV1Api(api_client=self.oapi_client)
700-
# self.batch_api = self.kclient.BatchV1Api(api_client=self.kapi_client) # for job api
701-
702698
@property
703699
def _identifying_attrs(self):
704700
"""
@@ -933,7 +929,10 @@ def get_pod(self, name, namespace=None):
933929
else:
934930
pod = self.get_ocp_obj(resource_type=self.v1_pod, name=name)
935931

936-
return Pod(system=self, name=pod.metadata.name, namespace=pod.metadata.namespace, raw=pod)
932+
return RHOpenShiftPod(system=self,
933+
name=pod.metadata.name,
934+
namespace=pod.metadata.namespace,
935+
raw=pod)
937936

938937
def create_vm(self, name, **kwargs):
939938
raise NotImplementedError('This function has not yet been implemented.')
@@ -950,7 +949,8 @@ def list_pods(self, namespace=None):
950949
list of wrapanapi.entities.Vm
951950
"""
952951
return [
953-
Pod(system=self, name=pod.metadata.name, namespace=pod.metadata.namespace, raw=pod)
952+
RHOpenShiftPod(system=self, name=pod.metadata.name, namespace=pod.metadata.namespace,
953+
raw=pod)
954954
for pod in self.v1_pod.get(namespace=namespace).items]
955955

956956
def wait_project_exist(self, name, wait=60):
@@ -976,22 +976,22 @@ def create_project(self, name, description=None, **kwargs):
976976

977977
project = self.v1_project.create(body=proj)
978978
self.wait_project_exist(name=name)
979-
return Project(system=self, name=project.metadata.name, raw=project)
979+
return RHOpenShiftProject(system=self, name=project.metadata.name, raw=project)
980980

981981
def find_projects(self, *args, **kwargs):
982982
raise NotImplementedError
983983

984984
def get_project(self, name):
985985
project = self.v1_project.get(name=name)
986986

987-
return Project(system=self, name=project.metadata.name, raw=project)
987+
return RHOpenShiftProject(system=self, name=project.metadata.name, raw=project)
988988

989989
get_vm = get_project
990990

991991
def list_project(self, namespace=None):
992992

993993
return [
994-
Project(system=self, name=project.metadata.name, raw=project)
994+
RHOpenShiftProject(system=self, name=project.metadata.name, raw=project)
995995
for project in self.v1_project.get(namespace=namespace).items]
996996

997997
list_vms = list_project
@@ -1847,7 +1847,6 @@ def read_pod_log(self, namespace, name):
18471847
"""
18481848
return self.v1_pod.log.get(name=name, namespace=namespace)
18491849

1850-
18511850
def start_vm(self, vm_name):
18521851
"""Starts a vm.
18531852
@@ -1987,5 +1986,5 @@ def run_command(self, namespace, name, cmd, **kwargs):
19871986
"""
19881987
# there are some limitations and this code isn't robust enough due to
19891988
# https://github.com/kubernetes-client/python/issues/58
1990-
return self.v1_pod.exec.post(namespace=namespace, name=name, command=cmd, stdout=True,
1989+
return self.v1_pod.exec(namespace=namespace, name=name, command=cmd, stdout=True,
19911990
stderr=True, **kwargs)

0 commit comments

Comments
 (0)