Skip to content

Commit 53d36ba

Browse files
lijianguoduanhongyi
authored andcommitted
feat(controller):add drycc resource cmd
1 parent 720ebe3 commit 53d36ba

3 files changed

Lines changed: 23 additions & 21 deletions

File tree

rootfs/api/models/resource.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def log(self, message, level=logging.INFO):
9292
This prefixes log messages with an application "tag" that the customized
9393
drycc-logspout will be on the lookout for. When it's seen, the message-- usually
9494
an application event of some sort like releasing or scaling, will be considered
95-
as "belonging" to the application instead of the contoller and will be handled
95+
as "belonging" to the application instead of the controller and will be handled
9696
accordingly.
9797
"""
9898
logger.log(level, "[{}]: {}".format(self.uuid, message))
@@ -131,6 +131,7 @@ def unbind(self, *args, **kwargs):
131131
self._scheduler.servicecatalog.get_binding(self.app.id, self.name)
132132
self._scheduler.servicecatalog.delete_binding(self.app.id, self.name)
133133
self.binding = None
134+
self.data = {}
134135
self.save()
135136
except KubeException as e:
136137
raise ServiceUnavailable("Could not unbind resource {} for application {}".format(self.name, self.app_id)) from e # noqa
@@ -175,6 +176,7 @@ def retrieve(self, *args, **kwargs):
175176
self.app.id, self.name).json()
176177
self.status = resp_i.get('status', {}).\
177178
get('lastConditionState')
179+
self.options = resp_i.get('spec', {}).get('parameters', {})
178180
update_flag = True
179181
except KubeException as e:
180182
logger.info("retrieve instance info error: {}".format(e))
@@ -185,7 +187,6 @@ def retrieve(self, *args, **kwargs):
185187
self.app.id, self.name).json()
186188
self.binding = resp_b.get('status', {}).\
187189
get('lastConditionState')
188-
self.options = resp_b.get('spec', {}).get('parameters', {})
189190
update_flag = True
190191
secret_name = resp_b.get('spec', {}).get('secretName')
191192
if secret_name:
@@ -197,7 +198,7 @@ def retrieve(self, *args, **kwargs):
197198
logger.info("retrieve binding info error: {}".format(e))
198199
if update_flag is True:
199200
self.save()
200-
if self.status and self.binding:
201+
if self.status == "Ready" and self.binding == "Ready":
201202
return True
202203
else:
203204
return False

rootfs/api/settings/production.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@
392392
'default': {
393393
'ENGINE': 'django.db.backends.postgresql',
394394
'NAME': os.environ.get(
395-
'DRYCC_DATABASE_NAME', os.environ.get('DRYCC_DATABASE_USER', 'drycc_controller')),
396-
'USER': os.environ.get('DRYCC_DATABASE_USER', 'drycc_controller'),
397-
'PASSWORD': os.environ.get('DRYCC_DATABASE_PASSWORD', '123456'),
398-
'HOST': os.environ.get('DRYCC_DATABASE_SERVICE_HOST', '192.168.6.50'),
395+
'DRYCC_DATABASE_NAME', os.environ.get('DRYCC_DATABASE_USER', 'drycc')),
396+
'USER': os.environ.get('DRYCC_DATABASE_USER', ''),
397+
'PASSWORD': os.environ.get('DRYCC_DATABASE_PASSWORD', ''),
398+
'HOST': os.environ.get('DRYCC_DATABASE_SERVICE_HOST', ''),
399399
'PORT': os.environ.get('DRYCC_DATABASE_SERVICE_PORT', 5432),
400400
# https://docs.djangoproject.com/en/1.11/ref/databases/#persistent-connections
401401
'CONN_MAX_AGE': 600,

rootfs/api/tests/test_resource.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,22 @@ def test_resource_delete(self, mock_requests):
102102
response = self.client.delete(url)
103103
self.assertEqual(response.status_code, 204)
104104

105-
def test_resource_update(self, mock_requests):
106-
"""
107-
Test that resource is delete from a app
108-
"""
109-
# create
110-
app_id = self.create_app()
111-
data = {'name': 'mysql', 'plan': 'mysql:5.6'}
112-
self.client.post('/v2/apps/{}/resources'.format(app_id), data=data)
113105

114-
# Update
115-
url = '/v2/apps/{app_id}/resources/{name}'.format(app_id=app_id,
116-
name='mysql')
117-
data = {'plan': 'mysql:5.7'}
118-
response = self.client.put(url, data=data)
119-
self.assertEqual(response.status_code, 200)
106+
# def test_resource_update(self, mock_requests):
107+
# """
108+
# Test that update resource from a app, Associated with apply_async
109+
# """
110+
# # create
111+
# app_id = self.create_app()
112+
# data = {'name': 'mysql', 'plan': 'mysql:5.6'}
113+
# self.client.post('/v2/apps/{}/resources'.format(app_id), data=data)
114+
#
115+
# # Update
116+
# url = '/v2/apps/{app_id}/resources/{name}'.format(app_id=app_id,
117+
# name='mysql')
118+
# data = {'plan': 'mysql:5.7'}
119+
# response = self.client.put(url, data=data)
120+
# self.assertEqual(response.status_code, 200)
120121

121122
def test_resource_bind(self, mock_requests):
122123
# create

0 commit comments

Comments
 (0)