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
1diff --git a/charms/focal/autopkgtest-cloud-worker/layer.yaml b/charms/focal/autopkgtest-cloud-worker/layer.yaml
2index 692d9af..70be935 100644
3--- a/charms/focal/autopkgtest-cloud-worker/layer.yaml
4+++ b/charms/focal/autopkgtest-cloud-worker/layer.yaml
5@@ -29,4 +29,5 @@ options:
6 - python3-openstackclient
7 - python3-swiftclient
8 - ssmtp
9+ - vim
10 include_system_packages: true
11diff --git a/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py b/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py
12index 4b5b22d..eaf76e4 100644
13--- a/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py
14+++ b/charms/focal/autopkgtest-cloud-worker/reactive/autopkgtest_cloud_worker.py
15@@ -4,6 +4,7 @@ import json
16 import os
17 import socket
18 import subprocess
19+from pathlib import Path
20 from textwrap import dedent
21
22 import pygit2
23@@ -51,6 +52,23 @@ AUTOPKGTEST_PER_PACKAGE_CLONE_LOCATION = (
24 RABBITMQ_CRED_PATH = os.path.expanduser("~ubuntu/rabbitmq.cred")
25
26
27+@when("apt.installed.vim")
28+def configure_vim():
29+ status.maintenance("Configuring vim")
30+ Path("/etc/vim/vimrc.local").write_text(
31+ """" autopkgtest-cloud vimrc, nicer for admins
32+" This file is written by the autopkgtest-cloud charm, do not edit manually, or
33+" you may loose your changes.
34+set background=dark " lighter colors by default
35+set number " show line numbers
36+set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,nbsp:‡ " set display of special characters
37+set list " show those special characters
38+highlight ExtraWhitespace ctermbg=red guibg=red " highlight extra whitespaces
39+match ExtraWhitespace /\\s\\+$\\| \\+\\ze\\t/ " define the extra whitespaces
40+ """
41+ )
42+
43+
44 @when_not("autopkgtest.autopkgtest_cloud_symlinked")
45 def symlink_autopkgtest_cloud():
46 status.maintenance("Creating symlink to charmed autopkgtest-cloud code")
47diff --git a/charms/focal/autopkgtest-web/layer.yaml b/charms/focal/autopkgtest-web/layer.yaml
48index 5c81bdb..6fd70d5 100644
49--- a/charms/focal/autopkgtest-web/layer.yaml
50+++ b/charms/focal/autopkgtest-web/layer.yaml
51@@ -21,4 +21,5 @@ options:
52 - python3-flask-openid
53 - python3-swiftclient
54 - python3-werkzeug
55+ - vim
56 include_system_packages: true
57diff --git a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
58index a228a0f..3aad037 100644
59--- a/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
60+++ b/charms/focal/autopkgtest-web/reactive/autopkgtest_web.py
61@@ -42,6 +42,23 @@ def install_apt_packages():
62 clear_flag("apt.queued_installs")
63
64
65+@when("apt.installed.vim")
66+def configure_vim():
67+ status.maintenance("Configuring vim")
68+ pathlib.Path("/etc/vim/vimrc.local").write_text(
69+ """" autopkgtest-cloud vimrc, nicer for admins
70+" This file is written by the autopkgtest-cloud charm, do not edit manually, or
71+" you may loose your changes.
72+set background=dark " lighter colors by default
73+set number " show line numbers
74+set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,nbsp:‡ " set display of special characters
75+set list " show those special characters
76+highlight ExtraWhitespace ctermbg=red guibg=red " highlight extra whitespaces
77+match ExtraWhitespace /\\s\\+$\\| \\+\\ze\\t/ " define the extra whitespaces
78+ """
79+ )
80+
81+
82 @when_not("autopkgtest-web.autopkgtest_web_symlinked")
83 def symlink_autopkgtest_cloud():
84 status.maintenance("Creating symlink to charmed autopkgtest-web code")

Subscribers

People subscribed via source and target branches