[master/rhel7-branch] Show error on invalid username attempts in TUI. (#1171778)
by Samantha N. Bueno
Previously, if a user entered an invalid username (e.g. "root"), no
error was shown and the username "root" was simply not created. This
could trouble users who were expecting a certain user to be created on
their systems, but saw no indication that there was a problem.
Resolves: rhbz#1171778
---
pyanaconda/ui/tui/spokes/user.py | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/pyanaconda/ui/tui/spokes/user.py b/pyanaconda/ui/tui/spokes/user.py
index 1c24d6d..7ef5b5d 100644
--- a/pyanaconda/ui/tui/spokes/user.py
+++ b/pyanaconda/ui/tui/spokes/user.py
@@ -81,9 +81,16 @@ class UserSpoke(FirstbootSpokeMixIn, EditTUISpoke):
# so that all of the properties are set at once
self.args._password = ""
+ self.errors = []
+
def refresh(self, args = None):
self.args._admin = "wheel" in self.args.groups
self.args._groups = ", ".join(self.args.groups)
+
+ # if we have any errors, display them
+ while len(self.errors) > 0:
+ print(self.errors.pop())
+
return EditTUISpoke.refresh(self, args)
@property
@@ -122,7 +129,9 @@ class UserSpoke(FirstbootSpokeMixIn, EditTUISpoke):
def apply(self):
if self.args.gecos and not self.args.name:
username = guess_username(self.args.gecos)
- if USERNAME_VALID.match(username):
+ if not USERNAME_VALID.match(username):
+ self.errors.append(_("Invalid user name: %s.\n" % username))
+ else:
self.args.name = guess_username(self.args.gecos)
self.args.groups = [g.strip() for g in self.args._groups.split(",") if g]
--
2.1.0
9 years
Updated: [rhinstaller/blivet/pulls/128 master] Include automatic and manual test documentation.
by dashea
This is my first attempt to bring some test documentation to blivet before actually trying to write any more tests. Summary of changes:
- modify existing Makefile target to include test documentation in the main document
- add dependency on Graphviz which is used to create inheritance graphs for test cases (used to outline which are the base test classes in Blivet). WARNING: may break Red The Docs if they don't have graphviz installed. Possibly needs a BuildRequires change for the spec file as well.
- update .gitignore
- add tests/README.rst with basic description of blivet's test suite.
--
To view this pull request on github, visit https://github.com/rhinstaller/blivet/pull/128
9 years
Updated: [rhinstaller/blivet/pulls/128 master] Include automatic and manual test documentation.
by dashea
This is my first attempt to bring some test documentation to blivet before actually trying to write any more tests. Summary of changes:
- modify existing Makefile target to include test documentation in the main document
- add dependency on Graphviz which is used to create inheritance graphs for test cases (used to outline which are the base test classes in Blivet). WARNING: may break Red The Docs if they don't have graphviz installed. Possibly needs a BuildRequires change for the spec file as well.
- update .gitignore
- add tests/README.rst with basic description of blivet's test suite.
--
To view this pull request on github, visit https://github.com/rhinstaller/blivet/pull/128
9 years
Updated: [rhinstaller/blivet/pulls/133 master] Fix tests deprecation warnings in a backward compatible way
by dashea
>From the original review in PR #120
@mulkieran
> Please use "with self.assertRaises" everywhere. It's just easier on the eyes.
This doesn't work b/c assertRaises and assertRaisesRegex are different. I'm not quite sure what do you mean but directly changing one for the other doesn't seem to work.
> Also, we always use six.PY2 and six.PY3 to check the python version for this kind of thing, not sys.version_info, so it's probably best to stick with that.
Fixed.
> I think you should be able to avoid modifying the class hierarchy to deal with the versioning problem in commit 3. You might consider modifying unittest.TestCase instead, for example.
Let me see how can I do this. Is there a place where I can hook into before the test cases are actually executed? If so I can monkey-patch unittest.TestCase instead of creating another base class.
--
To view this pull request on github, visit https://github.com/rhinstaller/blivet/pull/133
9 years
New: [rhinstaller/blivet/pulls/133 master] Fix tests deprecation warnings in a backward compatible way
by dashea
>From the original review in PR #120
@mulkieran
> Please use "with self.assertRaises" everywhere. It's just easier on the eyes.
This doesn't work b/c assertRaises and assertRaisesRegex are different. I'm not quite sure what do you mean but directly changing one for the other doesn't seem to work.
> Also, we always use six.PY2 and six.PY3 to check the python version for this kind of thing, not sys.version_info, so it's probably best to stick with that.
Fixed.
> I think you should be able to avoid modifying the class hierarchy to deal with the versioning problem in commit 3. You might consider modifying unittest.TestCase instead, for example.
Let me see how can I do this. Is there a place where I can hook into before the test cases are actually executed? If so I can monkey-patch unittest.TestCase instead of creating another base class.
--
To view this pull request on github, visit https://github.com/rhinstaller/blivet/pull/133
9 years
Updated: [rhinstaller/blivet/pulls/120 master] Run the test suite with both Python 2 and Python 3
by dashea
Since blivet is supposed to be compatible with both python 2 and 3 IMO it makes sense to run the test suite with both versions. (not to mention build the entire package with 2 or 3) At present only python2 is used to execute the test suite while python3 is used for pylint (due to pocketlint being python3 only).
This PR introduces the following changes:
- adds Makefile targets to execute the test suite under python 2 and 3 separately
- make test now runs the test suite with *both* python 2 and 3
- adds 2 separate targets to execute test suite with coverage report for python 2 and 3
- adds new check-requires target which checks if Requires:/BuildRequires and a few manual added ones are present
- replaces `/usr/bin/python` with `/usr/bin/env python` inside test cases. NOTE: I don't see any executable tests/*.py files but maybe this is a good measure. Otherwise this line doesn't have any effect and can be removed.
- updates the test cases to take care of several deprecation warnings coming from unittest. I've introduces a BlivetTestCase class which adds some aliases in case we're running with python2.
TODO:
There are still a few places which use hard-coded python version:
- Makefile uses PYTHON=python2 which is used in a few places calling setup.py
- some scripts/ use /usr/bin/python explicitly
- runpylint.py uses /usr/bin/python3 explicitly
make check uses pocketlint which is Python3 only. I have not looked into how hard it will be to build it for Python2. Will do it tomorrow.
Test results:
Running the test suite with python2 gives me 4 errors:
```
======================================================================
ERROR: testAvailabilityMDRAIDplugin (devices_test.dependencies_test.MockingDeviceDependenciesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/blivet/tests/devices_test/dependencies_test.py", line 64, in testAvailabilityMDRAIDplugin
self.assertIsNotNone(ActionCreateFormat(self.luks, fmt=getFormat("macefi")))
File "blivet/deviceaction.py", line 530, in __init__
raise ValueError("resource to create this format %s is unavailable" % fmt)
ValueError: resource to create this format non-existent macefi filesystem is unavailable
======================================================================
ERROR: testGetLabelArgs (formats_test.labeling_test.MethodsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/blivet/tests/formats_test/labeling_test.py", line 73, in testGetLabelArgs
reiserfs = self.fs["reiserfs"]
KeyError: 'reiserfs'
======================================================================
ERROR: testActionDependencies (action_test.DeviceActionTestCase)
Verify correct functioning of action dependencies.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/blivet/tests/action_test.py", line 944, in testActionDependencies
format_lv = ActionCreateFormat(testlv, fmt)
File "blivet/deviceaction.py", line 530, in __init__
raise ValueError("resource to create this format %s is unavailable" % fmt)
ValueError: resource to create this format non-existent None is unavailable
======================================================================
ERROR: testContainerActions (action_test.DeviceActionTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/blivet/tests/action_test.py", line 1122, in testContainerActions
fmt=new_lv_format)
File "tests/storagetestcase.py", line 245, in scheduleCreateFormat
action = blivet.deviceaction.ActionCreateFormat(device, fmt)
File "blivet/deviceaction.py", line 530, in __init__
raise ValueError("resource to create this format %s is unavailable" % fmt)
ValueError: resource to create this format non-existent xfs filesystem is unavailable
----------------------------------------------------------------------
Ran 467 tests in 704.377s
FAILED (errors=4, skipped=319)
```
Running with python3 gives me much more of the type:
```
======================================================================
ERROR: testMountingXFS (formats_test.selinux_test.SELinuxContextTestCase)
XFS does not have a lost+found directory.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/blivet/tests/formats_test/selinux_test.py", line 67, in testMountingXFS
an_fs = fs.XFS(device=self.loopDevices[0], label="test")
File "/root/blivet/blivet/formats/fs.py", line 101, in __init__
DeviceFormat.__init__(self, **kwargs)
File "/root/blivet/blivet/formats/__init__.py", line 186, in __init__
self.device = kwargs.get("device")
File "/root/blivet/blivet/formats/__init__.py", line 315, in <lambda>
lambda f,d: f._setDevice(d),
File "/root/blivet/blivet/formats/__init__.py", line 306, in _setDevice
error_msg = self._deviceCheck(devspec)
File "/root/blivet/blivet/formats/__init__.py", line 301, in _deviceCheck
if devspec and not devspec.startswith("/"):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
----------------------------------------------------------------------
I'm running on a recent F22 system upgraded to packages from the Rawhide repo. Let me know how would you like to proceed.
```
--
To view this pull request on github, visit https://github.com/rhinstaller/blivet/pull/120
9 years