Skip to content

Commit

Permalink
1.6.0
Browse files Browse the repository at this point in the history
Changelog:
* Add support for Ansible 2.9.
* Add RU locale.
* Some GUI and API optimization and fixes.

See merge request polemarch/ce!177
  • Loading branch information
onegreyonewhite committed Dec 13, 2019
2 parents a640db9 + e2bef43 commit b7b026e
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 58 deletions.
1 change: 0 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ code_style:
refs:
- merge_requests
- web
- master
retry: 2

py37-coverage:
Expand Down
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"devel": true,

"globals": {
"_translate": true,
"addCssClassesToElement": true,
"ApiConnector": true,
"api_connector_config": true,
Expand Down
22 changes: 8 additions & 14 deletions doc/api_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ info:
library: 1.5.2
vstutils: 2.11.2
django: 2.2.7
ansible: 2.8.7
ansible: 2.9.2
version: v2
host: localhost:8080
schemes:
Expand Down Expand Up @@ -11423,7 +11423,7 @@ definitions:
view_field: path
args:
title: Args
description: module arguments
description: host pattern
type: string
background:
title: Background
Expand All @@ -11436,7 +11436,7 @@ definitions:
default: false
become_method:
title: Become method
description: privilege escalation method to use (default=%default), use `ansible-doc
description: privilege escalation method to use (default=sudo), use `ansible-doc
-t become -l` to list valid choices.
type: string
become_user:
Expand Down Expand Up @@ -11479,11 +11479,6 @@ definitions:
$ref: '#/definitions/Inventory'
value_field: id
view_field: name
key_file:
title: Key file
description: use this file to authenticate the connection
type: string
format: secretfile
limit:
title: Limit
description: further limit selected hosts to an additional pattern
Expand Down Expand Up @@ -11602,14 +11597,18 @@ definitions:
$ref: '#/definitions/Playbook'
value_field: playbook
view_field: name
args:
title: Args
description: Playbook(s)
type: string
become:
title: Become
description: run operations with become (does not imply password prompting)
type: boolean
default: false
become_method:
title: Become method
description: privilege escalation method to use (default=%default), use `ansible-doc
description: privilege escalation method to use (default=sudo), use `ansible-doc
-t become -l` to list valid choices.
type: string
become_user:
Expand Down Expand Up @@ -11662,11 +11661,6 @@ definitions:
$ref: '#/definitions/Inventory'
value_field: id
view_field: name
key_file:
title: Key file
description: use this file to authenticate the connection
type: string
format: secretfile
limit:
title: Limit
description: further limit selected hosts to an additional pattern
Expand Down
2 changes: 1 addition & 1 deletion polemarch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"VST_ROOT_URLCONF": os.getenv("VST_ROOT_URLCONF", 'vstutils.urls'),
}

__version__ = "1.5.2"
__version__ = "1.6.0"

prepare_environment(**default_settings)
6 changes: 3 additions & 3 deletions polemarch/api/v2/swagger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from vstutils.api import swagger
from vstutils.api.schema.info import api_info_dict, openapi
from ...main.utils import AnsibleArgumentsReference

api_info_dict = swagger.api_info_dict.copy()
api_info_dict = api_info_dict.copy()
api_info_dict['x-versions']['ansible'] = AnsibleArgumentsReference().version

api_info = swagger.openapi.Info(**api_info_dict)
api_info = openapi.Info(**api_info_dict)
4 changes: 2 additions & 2 deletions polemarch/main/models/vars.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pylint: disable=protected-access,no-member
from __future__ import unicode_literals
from typing import Any, NoReturn, Tuple, Dict, List, Text
from typing import Any, NoReturn, Tuple, Dict, List, Text, Union
import logging
import uuid

Expand Down Expand Up @@ -137,7 +137,7 @@ def set_vars(self, variables) -> NoReturn:
for key, value in other_vars.items():
self.variables.create(key=key, value=value)

def get_vars(self) -> [OrderedDict, Dict]:
def get_vars(self) -> Union[OrderedDict, Dict]:
qs = self.variables.all().sort_by_key().values_list('key', 'value')
return reduce(update_boolean, self.BOOLEAN_VARS, OrderedDict(qs))

Expand Down
23 changes: 20 additions & 3 deletions polemarch/main/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ def setUp(self):

def test_api_versions_list(self):
result = self.get_result("get", "/api/")
self.assertEqual(len(result), 3)
self.assertTrue(result.get(self._settings('VST_API_VERSION'), False))
self.assertEqual(len(result['available_versions']), 1)
self.assertTrue(result['available_versions'].get(self._settings('VST_API_VERSION'), False))
self.assertTrue(result.get('openapi', False))

def test_api_v1_list(self):
Expand All @@ -370,7 +370,7 @@ def test_api_v1_list(self):

def test_api_router(self):
result = self.get_result('get', "/api/?format=json")
url = result[self._settings('VST_API_VERSION')].replace("http://testserver", "")
url = result['available_versions'][self._settings('VST_API_VERSION')].replace("http://testserver", "")
self.get_result('get', url)

def _generate_history(self, days_ago, count, status="OK"):
Expand Down Expand Up @@ -470,3 +470,20 @@ def test_bulk_unsupported(self):
self.assertIn("set", result["operations_types"])
self.assertIn("del", result["operations_types"])
self.assertIn("mod", result["operations_types"])

def test_lang(self):
bulk_data = [
{'data_type': ['_lang'], 'method': 'get'},
{'data_type': ['_lang', 'en'], 'method': 'get'},
{'data_type': ['_lang', 'ru'], 'method': 'get'},
]

results = self.make_bulk(bulk_data)
self.assertEqual(results[0]['status'], 200)
self.assertEqual(results[0]['data']['count'], 2)
self.assertEqual(results[1]['data']['code'], 'en')
self.assertEqual(results[1]['data']['name'], 'English')
self.assertEqual(results[1]['data']['translations']['pmwuserscounter'], 'users counter')
self.assertEqual(results[2]['data']['code'], 'ru')
self.assertEqual(results[2]['data']['name'], 'Russian')
self.assertEqual(results[2]['data']['translations']['pmwuserscounter'], 'счетчик пользователей')
29 changes: 27 additions & 2 deletions polemarch/main/tests/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ class OApiTestCase(BaseTestCase):

@skipUnless(openapi_schema_yaml.is_file(), "OpenApi schema file doesn't exist")
def test_openapi_schema(self):
'''
Regenerate new doc schema:
Examples:
.. sourcecode:: bash
python -m polemarch generate_swagger \
--format yaml \
--overwrite \
--url 'http://localhost:8080/' \
--user admin \
-m doc/api_schema.yaml
'''
schema = self.get_result('get', '/api/openapi/?format=openapi')

with openapi_schema_yaml.open('r') as fin:
Expand All @@ -23,5 +36,17 @@ def test_openapi_schema(self):
openapi_schema_yml['schemes'][0] = 'https'
openapi_schema_yml['info']['contact'] = schema['info']['contact']
openapi_schema_yml['info']['x-versions'] = schema['info']['x-versions']

self.assertDictEqual(openapi_schema_yml, schema)
openapi_schema_yml['info']['x-links'] = schema['info']['x-links']

for key in list(filter(lambda x: 'Ansible' in x, openapi_schema_yml['definitions'].keys())):
del openapi_schema_yml['definitions'][key]
del schema['definitions'][key]

for key, value in openapi_schema_yml.items():
cmp_value = schema.get(key, None)
if isinstance(value, dict):
self.assertDictEqual(value, cmp_value, key)
elif isinstance(value, list):
self.assertListEqual(value, cmp_value, key)
else:
self.assertEqual(value, cmp_value, key)
23 changes: 17 additions & 6 deletions polemarch/static/css/polemarch-gui.css
Original file line number Diff line number Diff line change
Expand Up @@ -349,23 +349,34 @@ body {
display: block;
}

@media (max-width: 452px) {
#period-list {
width: 100%!important;
margin-top: 10px;
}


.chart-period-select-wrapper {
display: flex;
margin-right: 10px;
}

.chart-period-select {
max-width: 145px;
width: 100%;
height: 30px!important;
line-height: 30px;
padding: 3px 12px;
display: inline-block;
float: left;
}

@media (max-width: 452px) {
#period-list {
width: 100%!important;
margin-top: 10px;
}

.chart-period-select-wrapper {
margin-right: 0;
}

}

.guifield-one_history_boolean .boolean-true, .guifield-one_history_boolean .boolean-false{
font-size: 24px;
}
Expand Down
2 changes: 1 addition & 1 deletion polemarch/static/js/pmCustomizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const pmSkinDefaultMixin = {

chart_axes_text_color: {
color_var:"--chart-axes-text-color",
title:'Chart legend text color',
title:'Chart axes text color',
format:'color',
default:"#666666",
// priority: 53,
Expand Down
20 changes: 12 additions & 8 deletions polemarch/static/js/pmDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ guiWidgets.history_chart = class HistoryChart extends guiWidgets.line_chart {
}

datasets.push({
label: line.title || line.name,
label: _translate((line.title || line.name).toLowerCase()).toUpperCase(),
data: this._formChartDataDatasets_oneLine(line, raw_data, labels),
borderColor: this._getChartLineColor(line),
backgroundColor: this._getChartLineColor(line, true),
Expand Down Expand Up @@ -338,12 +338,12 @@ guiWidgets.history_chart = class HistoryChart extends guiWidgets.line_chart {
* Sets Dashboard counter widgets.
*/
[
{name: 'pmwTemplatesCounter', title: 'template', sort: 1, active: true,},
{name: 'pmwProjectsCounter', title: 'projects', sort: 2, active: true, url: '/project'},
{name: 'pmwInventoriesCounter', title: 'inventories', sort: 3, active: true, url: '/inventory'},
{name: 'pmwGroupsCounter', title: 'groups', sort: 4, active: true, url: '/group'},
{name: 'pmwHostsCounter', title: 'hosts', sort: 5, active: true, url: '/host'},
{name: 'pmwUsersCounter', title: 'users', sort: 6, active: true, url: '/user'},
{name: 'pmwTemplatesCounter', title: 'templates counter', sort: 1, active: true,},
{name: 'pmwProjectsCounter', title: 'projects counter', sort: 2, active: true, url: '/project'},
{name: 'pmwInventoriesCounter', title: 'inventories counter', sort: 3, active: true, url: '/inventory'},
{name: 'pmwGroupsCounter', title: 'groups counter', sort: 4, active: true, url: '/group'},
{name: 'pmwHostsCounter', title: 'hosts counter', sort: 5, active: true, url: '/host'},
{name: 'pmwUsersCounter', title: 'users counter', sort: 6, active: true, url: '/user'},
].forEach(item => {
guiDashboard.widgets[item.name] = new guiWidgets.counter(item);
});
Expand All @@ -357,7 +357,7 @@ guiDashboard.widgets.pmwChartWidget = new guiWidgets.history_chart(
lines: {
all_tasks: {
name: "all_tasks",
title: "All tasks",
// title: "All tasks",
color: "#1f77b4",
bg_color: "rgba(31, 119, 180, 0.3)",
active: true,
Expand Down Expand Up @@ -486,6 +486,10 @@ guiDashboard.updateSettings = function(settings) {
guiLocalSettings.set('chart_line_settings', settings.chartLineSettings);
guiDashboard.updateChartLineSettings(settings.chartLineSettings);
}

if(settings.lang) {
app.setLanguage(settings.lang);
}
};

if(guiLocalSettings.get('widget_settings')) {
Expand Down
16 changes: 14 additions & 2 deletions polemarch/static/js/pmUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const user_settings_page_edit_mixin = {

guiDashboard.updateSettings(instance.data);

guiPopUp.success('User settings were successfully saved.');
guiPopUp.success(this.$t('User settings were successfully saved.'));

let url = this.getRedirectUrl({instance:instance});

Expand Down Expand Up @@ -98,6 +98,17 @@ function prepareUserSettingsViews(base_path) {
deleteUserSettingsPageNewView(base_path + 'new/');
}

/**
* Signal, that adds 'lang' field to UserSettings model's fields.
* It supposed to be first during rendering.
*/
tabSignal.connect('openapi.loaded', openapi => {
openapi.definitions.UserSettings.properties = {
lang: {format: 'choices', title: 'language', description: 'application interface language'},
...openapi.definitions.UserSettings.properties,
};
});

/**
* Signal, that edits options of UserSettings model's fields.
*/
Expand All @@ -124,8 +135,9 @@ tabSignal.connect("models[UserSettings].fields.beforeInit", (fields => {
title: 'Skin settings',
format: 'hidden',
};
}));

fields.lang.enum = app.languages.map(lang => lang.code);
}));
/**
* Emits signals for UserSettings views.
*/
Expand Down
6 changes: 3 additions & 3 deletions polemarch/static/templates/pmHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h1>
<section>
<div class="card card-info">
<div class="card-header with-border card-header-custom">
<span>Execution output</span>
<span>{{ $t('execution output') | capitalize }}</span>


<!-- Button for collapse and expand this section -->
Expand Down Expand Up @@ -140,7 +140,7 @@ <h1>
<section class="col-lg-12 col-xl-3">
<div class="card card-info">
<div class="card-header with-border card-header-custom">
<span>Details</span>
<span>{{ $t('detail') | capitalize }}</span>
<!-- Button for collapse and expand this section -->
<button type="button" class="btn btn-card-tool btn-sm btn-light btn-icon"
@click="information_toggle = !information_toggle" style="float: right;"
Expand Down Expand Up @@ -173,7 +173,7 @@ <h1>
<script type="text/x-template" id="template_history_stdout">
<div>
<span>
<b>stdout</b> (<a :href="raw_stdout_link" target="_blank" class="revers-color">Full raw stdout</a>)
<b>{{ $t('stdout') }}</b> (<a :href="raw_stdout_link" target="_blank" class="revers-color">{{ $t('full raw stdout') | capitalize }}</a>)
<i class="fa fa-spinner fa-pulse fa-fw" v-show="loading"></i>
</span>
<pre class="history-stdout" v-html="linesHTML" @scroll="scrollHandler"></pre>
Expand Down
Loading

0 comments on commit b7b026e

Please sign in to comment.