Added test configuration for uds actor & fixed some texts

This commit is contained in:
Adolfo Gómez García 2019-12-19 12:54:30 +01:00
parent 3e905381ff
commit 7483a6f04f
6 changed files with 126 additions and 20 deletions

View File

@ -70,6 +70,8 @@ class UDSConfigDialog(QDialog):
self.ui.username.setText('') self.ui.username.setText('')
self.ui.password.setText('') self.ui.password.setText('')
self.ui.testButton.setEnabled(bool(config.master_token and config.host))
@property @property
def api(self) -> udsactor.rest.UDSServerApi: def api(self) -> udsactor.rest.UDSServerApi:
return udsactor.rest.UDSServerApi(self.ui.host.text(), self.ui.validateCertificate.currentIndex() == 1) return udsactor.rest.UDSServerApi(self.ui.host.text(), self.ui.validateCertificate.currentIndex() == 1)
@ -105,10 +107,40 @@ class UDSConfigDialog(QDialog):
def textChanged(self): def textChanged(self):
enableButtons = bool(self.ui.host.text() and self.ui.username.text() and self.ui.password.text() and self.ui.authenticators.currentText()) enableButtons = bool(self.ui.host.text() and self.ui.username.text() and self.ui.password.text() and self.ui.authenticators.currentText())
self.ui.registerButton.setEnabled(enableButtons) self.ui.registerButton.setEnabled(enableButtons)
self.ui.testButton.setEnabled(False) # Only registered information can be checked
def finish(self): def finish(self):
self.close() self.close()
def testUDSServer(self):
config: udsactor.types.ActorConfigurationType = udsactor.platform.store.readConfig()
if not config.master_token:
self.ui.testButton.setEnabled(False)
return
try:
api = udsactor.rest.UDSServerApi(config.host, config.validateCertificate)
if not api.test(config.master_token):
QMessageBox.information(
self,
'UDS Test',
'Current configured token seems to be invalid for {}. Please, request e new one.'.format(config.host),
QMessageBox.Ok
)
else:
QMessageBox.information(
self,
'UDS Test',
'Configuration for {} seems to be correct.'.format(config.host),
QMessageBox.Ok
)
except Exception:
QMessageBox.information(
self,
'UDS Test',
'Configured host {} seems to be inaccesible.'.format(config.host),
QMessageBox.Ok
)
def registerWithUDS(self): def registerWithUDS(self):
# Get network card. Will fail if no network card is available, but don't mind (not contempled) # Get network card. Will fail if no network card is available, but don't mind (not contempled)
data: udsactor.types.InterfaceInfoType = next(udsactor.platform.operations.getNetworkInfo()) data: udsactor.types.InterfaceInfoType = next(udsactor.platform.operations.getNetworkInfo())
@ -137,9 +169,12 @@ class UDSConfigDialog(QDialog):
log_level=self.ui.logLevelComboBox.currentIndex() log_level=self.ui.logLevelComboBox.currentIndex()
) )
) )
# Inform the user # Enables test button
self.ui.testButton.setEnabled(True)
# Informs the user
QMessageBox.information(self, 'UDS Registration', 'Registration with UDS completed.', QMessageBox.Ok) QMessageBox.information(self, 'UDS Registration', 'Registration with UDS completed.', QMessageBox.Ok)
except udsactor.rest.RESTError as e: except udsactor.rest.RESTError as e:
self.ui.testButton.setEnabled(False)
QMessageBox.critical(self, 'UDS Registration', 'UDS Registration error: {}'.format(e), QMessageBox.Ok) QMessageBox.critical(self, 'UDS Registration', 'UDS Registration error: {}'.format(e), QMessageBox.Ok)

View File

@ -66,11 +66,14 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Click to test the selecter parameters</string> <string>Click to register Actor with UDS Broker</string>
</property> </property>
<property name="whatsThis"> <property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Click on this button to test the server host and master key parameters.&lt;/p&gt;&lt;p&gt;A window will be displayed with results after the test is executed.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;This button will only be active if all parameters are filled.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Click on this button to register Actor with UDS Broker.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="text"> <property name="text">
<string>Register with UDS</string> <string>Register with UDS</string>
@ -98,10 +101,10 @@
</size> </size>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Cancel all changes and discard them</string> <string>Closes UDS Actor Configuration (discard pending changes if any)</string>
</property> </property>
<property name="whatsThis"> <property name="whatsThis">
<string>Discards all changes and closes the configuration window</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Exits the UDS Actor Configuration Tool&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="text"> <property name="text">
<string>Close</string> <string>Close</string>
@ -117,7 +120,7 @@
</rect> </rect>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="tab_uds"> <widget class="QWidget" name="tab_uds">
<attribute name="title"> <attribute name="title">
@ -170,7 +173,11 @@
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QComboBox" name="authenticators"/> <widget class="QComboBox" name="authenticators">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Select the UDS Broker authenticator for credentials validation&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="label_username"> <widget class="QLabel" name="label_username">
@ -185,7 +192,7 @@
<string>UDS user with administration rights (Will not be stored on template)</string> <string>UDS user with administration rights (Will not be stored on template)</string>
</property> </property>
<property name="whatsThis"> <property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Administrator user on UDS Server.&lt;/p&gt;&lt;p&gt;Note: This credential will not be stored on client. Will be used to obtain an unique key for this image.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Administrator user on UDS Server.&lt;/p&gt;&lt;p&gt;Note: This credential will not be stored on client. Will be used to obtain an unique token for this image.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -430,6 +437,34 @@
</widget> </widget>
</widget> </widget>
</widget> </widget>
<widget class="QPushButton" name="testButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>210</x>
<y>270</y>
<width>181</width>
<height>23</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>181</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Click to test existing configuration (disabled if no config found)</string>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Click on this button to test the server host and assigned toen.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Test configuration</string>
</property>
</widget>
</widget> </widget>
<resources> <resources>
<include location="uds.qrc"/> <include location="uds.qrc"/>
@ -595,6 +630,22 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>testButton</sender>
<signal>clicked()</signal>
<receiver>UdsActorSetupDialog</receiver>
<slot>testUDSServer()</slot>
<hints>
<hint type="sourcelabel">
<x>300</x>
<y>281</y>
</hint>
<hint type="destinationlabel">
<x>294</x>
<y>153</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>textChanged()</slot> <slot>textChanged()</slot>
@ -604,5 +655,6 @@
<slot>browseRunOnce()</slot> <slot>browseRunOnce()</slot>
<slot>browsePostConfig()</slot> <slot>browsePostConfig()</slot>
<slot>updateAuthenticators()</slot> <slot>updateAuthenticators()</slot>
<slot>testUDSServer()</slot>
</slots> </slots>
</ui> </ui>

View File

@ -58,7 +58,7 @@ def readConfig() -> types.ActorConfigurationType:
pre_command=uds.get('pre_command', None), pre_command=uds.get('pre_command', None),
runonce_command=uds.get('runonce_command', None), runonce_command=uds.get('runonce_command', None),
post_command=uds.get('post_command', None), post_command=uds.get('post_command', None),
log_level=int(uds.get('log_level', '1')), log_level=int(uds.get('log_level', '3')),
config=config, config=config,
data=data data=data
) )

View File

@ -101,7 +101,9 @@ class UDSApi: # pylint: disable=too-few-public-methods
try: try:
result = requests.post(self._apiURL(method), data=json.dumps(payLoad), headers=headers, verify=self._validateCert) result = requests.post(self._apiURL(method), data=json.dumps(payLoad), headers=headers, verify=self._validateCert)
if result.ok: if result.ok:
return result.json()['result'] j = result.json()
if 'error' not in j:
return j['result']
except requests.ConnectionError as e: except requests.ConnectionError as e:
raise RESTConnectionError(str(e)) raise RESTConnectionError(str(e))
except Exception as e: except Exception as e:
@ -114,7 +116,6 @@ class UDSApi: # pylint: disable=too-few-public-methods
raise RESTError(data) raise RESTError(data)
# #
# UDS Broker API access # UDS Broker API access
# #
@ -270,6 +271,12 @@ class UDSServerApi(UDSApi):
} }
self._doPost('log', payLoad) # Ignores result... self._doPost('log', payLoad) # Ignores result...
def test(self, master_token: str) -> bool:
payLoad = {
'token': master_token,
}
return self._doPost('test', payLoad) == 'ok'
class UDSClientApi(UDSApi): class UDSClientApi(UDSApi):
def __init__(self) -> None: def __init__(self) -> None:

View File

@ -2,12 +2,14 @@
# Form implementation generated from reading ui file 'setup-dialog.ui' # Form implementation generated from reading ui file 'setup-dialog.ui'
# #
# Created by: PyQt5 UI code generator 5.11.3 # Created by: PyQt5 UI code generator 5.13.2
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_UdsActorSetupDialog(object): class Ui_UdsActorSetupDialog(object):
def setupUi(self, UdsActorSetupDialog): def setupUi(self, UdsActorSetupDialog):
UdsActorSetupDialog.setObjectName("UdsActorSetupDialog") UdsActorSetupDialog.setObjectName("UdsActorSetupDialog")
@ -34,6 +36,7 @@ class Ui_UdsActorSetupDialog(object):
self.registerButton.setEnabled(False) self.registerButton.setEnabled(False)
self.registerButton.setGeometry(QtCore.QRect(10, 270, 181, 23)) self.registerButton.setGeometry(QtCore.QRect(10, 270, 181, 23))
self.registerButton.setMinimumSize(QtCore.QSize(181, 0)) self.registerButton.setMinimumSize(QtCore.QSize(181, 0))
self.registerButton.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
self.registerButton.setObjectName("registerButton") self.registerButton.setObjectName("registerButton")
self.closeButton = QtWidgets.QPushButton(UdsActorSetupDialog) self.closeButton = QtWidgets.QPushButton(UdsActorSetupDialog)
self.closeButton.setGeometry(QtCore.QRect(410, 270, 171, 23)) self.closeButton.setGeometry(QtCore.QRect(410, 270, 171, 23))
@ -180,9 +183,14 @@ class Ui_UdsActorSetupDialog(object):
self.logLevelComboBox.setItemText(3, "FATAL") self.logLevelComboBox.setItemText(3, "FATAL")
self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.logLevelComboBox) self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.logLevelComboBox)
self.tabWidget.addTab(self.tab_advanced, "") self.tabWidget.addTab(self.tab_advanced, "")
self.testButton = QtWidgets.QPushButton(UdsActorSetupDialog)
self.testButton.setEnabled(False)
self.testButton.setGeometry(QtCore.QRect(210, 270, 181, 23))
self.testButton.setMinimumSize(QtCore.QSize(181, 0))
self.testButton.setObjectName("testButton")
self.retranslateUi(UdsActorSetupDialog) self.retranslateUi(UdsActorSetupDialog)
self.tabWidget.setCurrentIndex(0) self.tabWidget.setCurrentIndex(1)
self.logLevelComboBox.setCurrentIndex(1) self.logLevelComboBox.setCurrentIndex(1)
self.closeButton.clicked.connect(UdsActorSetupDialog.finish) self.closeButton.clicked.connect(UdsActorSetupDialog.finish)
self.registerButton.clicked.connect(UdsActorSetupDialog.registerWithUDS) self.registerButton.clicked.connect(UdsActorSetupDialog.registerWithUDS)
@ -194,24 +202,26 @@ class Ui_UdsActorSetupDialog(object):
self.browseRunOnceButton.clicked.connect(UdsActorSetupDialog.browseRunOnce) self.browseRunOnceButton.clicked.connect(UdsActorSetupDialog.browseRunOnce)
self.host.editingFinished.connect(UdsActorSetupDialog.updateAuthenticators) self.host.editingFinished.connect(UdsActorSetupDialog.updateAuthenticators)
self.authenticators.currentTextChanged['QString'].connect(UdsActorSetupDialog.textChanged) self.authenticators.currentTextChanged['QString'].connect(UdsActorSetupDialog.textChanged)
self.testButton.clicked.connect(UdsActorSetupDialog.testUDSServer)
QtCore.QMetaObject.connectSlotsByName(UdsActorSetupDialog) QtCore.QMetaObject.connectSlotsByName(UdsActorSetupDialog)
def retranslateUi(self, UdsActorSetupDialog): def retranslateUi(self, UdsActorSetupDialog):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
UdsActorSetupDialog.setWindowTitle(_translate("UdsActorSetupDialog", "UDS Actor Configuration Tool")) UdsActorSetupDialog.setWindowTitle(_translate("UdsActorSetupDialog", "UDS Actor Configuration Tool"))
self.registerButton.setToolTip(_translate("UdsActorSetupDialog", "Click to test the selecter parameters")) self.registerButton.setToolTip(_translate("UdsActorSetupDialog", "Click to register Actor with UDS Broker"))
self.registerButton.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Click on this button to test the server host and master key parameters.</p><p>A window will be displayed with results after the test is executed.</p><p><br/></p><p>This button will only be active if all parameters are filled.</p></body></html>")) self.registerButton.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Click on this button to register Actor with UDS Broker.</p></body></html>"))
self.registerButton.setText(_translate("UdsActorSetupDialog", "Register with UDS")) self.registerButton.setText(_translate("UdsActorSetupDialog", "Register with UDS"))
self.closeButton.setToolTip(_translate("UdsActorSetupDialog", "Cancel all changes and discard them")) self.closeButton.setToolTip(_translate("UdsActorSetupDialog", "Closes UDS Actor Configuration (discard pending changes if any)"))
self.closeButton.setWhatsThis(_translate("UdsActorSetupDialog", "Discards all changes and closes the configuration window")) self.closeButton.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Exits the UDS Actor Configuration Tool</p></body></html>"))
self.closeButton.setText(_translate("UdsActorSetupDialog", "Close")) self.closeButton.setText(_translate("UdsActorSetupDialog", "Close"))
self.label_host.setText(_translate("UdsActorSetupDialog", "UDS Server")) self.label_host.setText(_translate("UdsActorSetupDialog", "UDS Server"))
self.host.setToolTip(_translate("UdsActorSetupDialog", "Uds Broker Server Addres. Use IP or FQDN")) self.host.setToolTip(_translate("UdsActorSetupDialog", "Uds Broker Server Addres. Use IP or FQDN"))
self.host.setWhatsThis(_translate("UdsActorSetupDialog", "Enter here the UDS Broker Addres using either its IP address or its FQDN address")) self.host.setWhatsThis(_translate("UdsActorSetupDialog", "Enter here the UDS Broker Addres using either its IP address or its FQDN address"))
self.label_auth.setText(_translate("UdsActorSetupDialog", "Authenticator")) self.label_auth.setText(_translate("UdsActorSetupDialog", "Authenticator"))
self.authenticators.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Select the UDS Broker authenticator for credentials validation</p></body></html>"))
self.label_username.setText(_translate("UdsActorSetupDialog", "Username")) self.label_username.setText(_translate("UdsActorSetupDialog", "Username"))
self.username.setToolTip(_translate("UdsActorSetupDialog", "UDS user with administration rights (Will not be stored on template)")) self.username.setToolTip(_translate("UdsActorSetupDialog", "UDS user with administration rights (Will not be stored on template)"))
self.username.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Administrator user on UDS Server.</p><p>Note: This credential will not be stored on client. Will be used to obtain an unique key for this image.</p></body></html>")) self.username.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Administrator user on UDS Server.</p><p>Note: This credential will not be stored on client. Will be used to obtain an unique token for this image.</p></body></html>"))
self.label_password.setText(_translate("UdsActorSetupDialog", "Password")) self.label_password.setText(_translate("UdsActorSetupDialog", "Password"))
self.password.setToolTip(_translate("UdsActorSetupDialog", "Password for user (Will not be stored on template)")) self.password.setToolTip(_translate("UdsActorSetupDialog", "Password for user (Will not be stored on template)"))
self.password.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Administrator password for the user on UDS Server.</p><p>Note: This credential will not be stored on client. Will be used to obtain an unique key for this image.</p></body></html>")) self.password.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Administrator password for the user on UDS Server.</p><p>Note: This credential will not be stored on client. Will be used to obtain an unique key for this image.</p></body></html>"))
@ -232,5 +242,7 @@ class Ui_UdsActorSetupDialog(object):
self.browsePostConfigButton.setText(_translate("UdsActorSetupDialog", "Browse")) self.browsePostConfigButton.setText(_translate("UdsActorSetupDialog", "Browse"))
self.label_loglevel.setText(_translate("UdsActorSetupDialog", "Log Level")) self.label_loglevel.setText(_translate("UdsActorSetupDialog", "Log Level"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_advanced), _translate("UdsActorSetupDialog", "Advanced")) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_advanced), _translate("UdsActorSetupDialog", "Advanced"))
self.testButton.setToolTip(_translate("UdsActorSetupDialog", "Click to test existing configuration (disabled if no config found)"))
self.testButton.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Click on this button to test the server host and assigned toen.</p></body></html>"))
self.testButton.setText(_translate("UdsActorSetupDialog", "Test configuration"))
from ui import uds_rc from ui import uds_rc

View File

@ -2,7 +2,7 @@
# Resource object code # Resource object code
# #
# Created by: The Resource Compiler for PyQt5 (Qt v5.11.3) # Created by: The Resource Compiler for PyQt5 (Qt v5.13.2)
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!