Merge ~hyask/autopkgtest-cloud:skia/vimrc into autopkgtest-cloud:master

Proposed by Skia
Status: Merged
Merged at revision: bbc5b2a7fe7d17e2e493b61738b74229a7b11f25
Proposed branch: ~hyask/autopkgtest-cloud:skia/vimrc
Merge into: autopkgtest-cloud:master
Diff against target: 84 lines (+37/-0)
4 files modified
charms/focal/autopkgtest-cloud-worker/layer.yaml (+1/-0)
charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py (+18/-0)
charms/focal/autopkgtest-web/layer.yaml (+1/-0)
charms/focal/autopkgtest-web/reactive/autopkgtest_web.py (+17/-0)
Reviewer Review Type Date Requested Status
Skia Approve
Tim Andersson Needs Fixing
Paride Legovini Abstain
Review via email: mp+463822@code.launchpad.net

Description of the change

Set a default vimrc on autopkgtest-cloud machines.

To post a comment you must log in.
Revision history for this message
Skia (hyask) wrote :

To have a quick look at what this enables, please `vim /tmp/test` on the bastion (production environment).

Revision history for this message
Paride Legovini (paride) :
review: Disapprove
Revision history for this message
Paride Legovini (paride) wrote :

I misclicked, I don't have an opinion on this one yet.

review: Abstain
Revision history for this message
Tim Andersson (andersson123) wrote :

given the vimrc config is duplicated in code in both of the charms with this approach, I think it'd be best to just have it in a file that's shared by both charms rather than have the config duplicated. Plus you can also then just symlink the vimrc (within autopkgtest-cloud) to /etc/vim/vimrc.local

review: Needs Fixing
Revision history for this message
Paride Legovini (paride) wrote :

I think this is fine and the settings are sensible, at least until we get a team member that uses terminals with a light background. :)

Very minor nit: there is some alignment issue in the inline comments (on the match ExtraWhitespace line), but maybe that's only happening on Launchpad.

As discussed in a side channel, is it fine to have this system wide as this is going into single purpose systems, and we often need to `sudo vim`, and in that case having the vimrc to the $HOME of the unprivileged user won't work.

+1 but needs CI fix, I see you added the disable=line-too-long, but it's still failing?

Revision history for this message
Tim Andersson (andersson123) wrote :

... I use light background, but I'm fine, as I'm clearly the minority here ...

Revision history for this message
Skia (hyask) wrote :

I've updated to fix the CI.

Here are my answers:
Tim: I totally agree that there is code duplication, and I don't like that. I couldn't find what mechanism we have in place to avoid that in the charms code. The current status seems to be to duplicate the code, since there are a lot of similar functions in both charms already. Do you know of anything that could help?

Paride: about the misalignment, this is on purpose in the Python code, since we need to backslash escaping. The goal was to have proper alignment in the resulting `vimrc` file.

Revision history for this message
Tim Andersson (andersson123) wrote :

The only mechanism I've used in the past is in this MP:
https://code.launchpad.net/~andersson123/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/457239

You can see config_file_check_common.py is symlinked to the relevant charm directories. The MP is unfinished and I believe the way I symlinked the file obviously isn't appropriate, so I need to fix that when I come back to it.

But yeah, the only suggestion I have is the primitive ape approach I've detailed above, symlink a common file to the relevant directories

Revision history for this message
Skia (hyask) wrote :

You mean the local symlink you pushed to the MP, with the whole `/home/tim/canonical/code/autopkgtest-cloud/infrastructure-tests-common/config_file_check_common.py` path? I doubt this is appropriate to push to a repo shared among us :-D

Jokes aside, yes, maybe a relative symlink could be pushed to reduce the copy-pasting, but I think we would spend better time really thinking about a proper solution to improve our charms.

Revision history for this message
Tim Andersson (andersson123) wrote :

yes I mean that xD

I agree. We should spend some time coming up with a better solution. If you think it's best to do that at another time and not do anything for this MP, I'm fine with that. I'd much rather have a symlink at the least but I'm not to fussed, do as you please

Revision history for this message
Skia (hyask) wrote :

Given your comments, our discussions, and the fact that this is not really dangerous for autopkgtest-cloud itself, I've gone ahead and merged this. :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/charms/focal/autopkgtest-cloud-worker/layer.yaml b/charms/focal/autopkgtest-cloud-worker/layer.yaml
index 692d9af..70be935 100644
--- a/charms/focal/autopkgtest-cloud-worker/layer.yaml
+++ b/charms/focal/autopkgtest-cloud-worker/layer.yaml
@@ -29,4 +29,5 @@ options:
29 - python3-openstackclient29 - python3-openstackclient
30 - python3-swiftclient30 - python3-swiftclient
31 - ssmtp31 - ssmtp
32 - vim
32 include_system_packages: true33 include_system_packages: true
diff --git a/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py b/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py
index 4b5b22d..eaf76e4 100644
--- a/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py
+++ b/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py
@@ -4,6 +4,7 @@ import json
4import os4import os
5import socket5import socket
6import subprocess6import subprocess
7from pathlib import Path
7from textwrap import dedent8from textwrap import dedent
89
9import pygit210import pygit2
@@ -51,6 +52,23 @@ AUTOPKGTEST_PER_PACKAGE_CLONE_LOCATION = (
51RABBITMQ_CRED_PATH = os.path.expanduser("~ubuntu/rabbitmq.cred")52RABBITMQ_CRED_PATH = os.path.expanduser("~ubuntu/rabbitmq.cred")
5253
5354
55@when("apt.installed.vim")
56def configure_vim():
57 status.maintenance("Configuring vim")
58 Path("/etc/vim/vimrc.local").write_text(
59 """" autopkgtest-cloud vimrc, nicer for admins
60" This file is written by the autopkgtest-cloud charm, do not edit manually, or
61" you may loose your changes.
62set background=dark " lighter colors by default
63set number " show line numbers
64set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,nbsp:‡ " set display of special characters
65set list " show those special characters
66highlight ExtraWhitespace ctermbg=red guibg=red " highlight extra whitespaces
67match ExtraWhitespace /\\s\\+$\\| \\+\\ze\\t/ " define the extra whitespaces
68 """
69 )
70
71
54@when_not("autopkgtest.autopkgtest_cloud_symlinked")72@when_not("autopkgtest.autopkgtest_cloud_symlinked")
55def symlink_autopkgtest_cloud():73def symlink_autopkgtest_cloud():
56 status.maintenance("Creating symlink to charmed autopkgtest-cloud code")74 status.maintenance("Creating symlink to charmed autopkgtest-cloud code")
diff --git a/charms/focal/autopkgtest-web/layer.yaml b/charms/focal/autopkgtest-web/layer.yaml
index 5c81bdb..6fd70d5 100644
--- a/charms/focal/autopkgtest-web/layer.yaml
+++ b/charms/focal/autopkgtest-web/layer.yaml
@@ -21,4 +21,5 @@ options:
21 - python3-flask-openid21 - python3-flask-openid
22 - python3-swiftclient22 - python3-swiftclient
23 - python3-werkzeug23 - python3-werkzeug
24 - vim
24 include_system_packages: true25 include_system_packages: true
diff --git a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
index a228a0f..3aad037 100644
--- a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
+++ b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
@@ -42,6 +42,23 @@ def install_apt_packages():
42 clear_flag("apt.queued_installs")42 clear_flag("apt.queued_installs")
4343
4444
45@when("apt.installed.vim")
46def configure_vim():
47 status.maintenance("Configuring vim")
48 pathlib.Path("/etc/vim/vimrc.local").write_text(
49 """" autopkgtest-cloud vimrc, nicer for admins
50" This file is written by the autopkgtest-cloud charm, do not edit manually, or
51" you may loose your changes.
52set background=dark " lighter colors by default
53set number " show line numbers
54set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,nbsp:‡ " set display of special characters
55set list " show those special characters
56highlight ExtraWhitespace ctermbg=red guibg=red " highlight extra whitespaces
57match ExtraWhitespace /\\s\\+$\\| \\+\\ze\\t/ " define the extra whitespaces
58 """
59 )
60
61
45@when_not("autopkgtest-web.autopkgtest_web_symlinked")62@when_not("autopkgtest-web.autopkgtest_web_symlinked")
46def symlink_autopkgtest_cloud():63def symlink_autopkgtest_cloud():
47 status.maintenance("Creating symlink to charmed autopkgtest-web code")64 status.maintenance("Creating symlink to charmed autopkgtest-web code")

Subscribers

People subscribed via source and target branches