Fritz 7490: Root cause for Port mapping failure issue on a vagrant virtual machine

tl;dr

The root cause is that the default route was not set to the router's IP address.

My journey to resolve the issue:

The issue is that port mapping can work with my raspberry pi while it couldn't work with a virtual machine in the same LAN. I firstly think it must be a bug from the router. I upgrade the router to its latest firmware, but it still doesn't work. I google back and forth, I learned much from all kinds of answers, but they were just not my case. I almost decided to give up.

Then I found the following answer from E. van Putten, he answered this question and nobody gave his answer a "Like"!!!

In case you landed on this page because you can't reach a server running inside a Xen Guest from the internet (but can connect locally), then read on...

  1. The fritzbox can get confused by different OS'es appearing from the same MAC-address etc. (could happen while you are setting up / experimenting with Xen)
  2. The fritzbox has seemingly duplicate entries in the list, but with different settings, you need to delete the portmap from the incorrect entry, cleanup the list and reapply the portmap settings.
  3. It might be that your guest OS has no default gateway IP-address set. You'd expect a default gateway set to the local IP-address of your fritzbox.

The symptoms of a missing default gateway is that your LAN PCs can access the server running inside the guest just fine, but external users from the internet cannot connect.

He gave three possible causes, and my case is the third one! here's my solution

opts = {
    :name => "yt-gateway",
    :ip => "192.168.178.173",
    :mem => "1024",
    :cpu => "1"
}
Vagrant.configure("2") do |config|
  config.vm.box = "bento/ubuntu-20.04"
  config.vm.hostname = opts[:name]
  config.vm.network :public_network, ip: opts[:ip], bridge: "eno1"
  config.vm.provision "shell", run: "always", inline: "route add default gw 192.168.178.1 || true"
  config.vm.provider "virtualbox" do |v|
    v.name = opts[:name]
    v.customize ["modifyvm", :id, "--memory", opts[:mem]]
    v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
    v.customize ["modifyvm", :id, "--name", opts[:name]]
  end
end

I love you E. van!

Setup PiVPN on a Vagrant virtual machine that is running Ubuntu 20.04

PiVPN should be easy to setup at any debian/ubuntu family distribution. However, my case wasn't.

  1. The first issue I met is Can't call method "set" on an undefined value at /usr/share/perl5/Debconf/FrontEnd.pm line 126, line 5., and I found a useful anwser from https://github.com/pivpn/pivpn/issues/718, which is
apt-get install --reinstall debconf

it worked! though I don't know the root cause.

  1. The second issue is rather weird, it simple stuck after showing ::: Backing up the openvpn folder... message. What's wrong with that on earth? Unfortunately, I couldn't find anything useful from google/stackoverflow.... I have to find out the root cause by myself.

ps -ef command shows there is a wget -qO- https://github.com/OpenVPN/easy-rsa/releases/download/v3.0.7/EasyRSA-3.0.7.tgz process running. Why it is running so long and looks never end? I copied the wget command and run it manually. aha, I found the cause!

wget https://github.com/OpenVPN/easy-rsa/releases/download/v3.0.7/EasyRSA-3.0.7.tgz
--2021-10-10 23:01:15--  https://github.com/OpenVPN/easy-rsa/releases/download/v3.0.7/EasyRSA-3.0.7.tgz
Resolving github.com (github.com)... 52.64.108.95
Connecting to github.com (github.com)|52.64.108.95|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/4519663/0fa24e00-72ba-11ea-9afe-6e5829eec4a4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20211010%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211010T230115Z&X-Amz-Expires=300&X-Amz-Signature=1acb19fd17e7cb4f74c5695b194dc2040b13d9649da64b191a53591758471718&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=4519663&response-content-disposition=attachment%3B%20filename%3DEasyRSA-3.0.7.tgz&response-content-type=application%2Foctet-stream [following]
--2021-10-10 23:01:15--  https://github-releases.githubusercontent.com/4519663/0fa24e00-72ba-11ea-9afe-6e5829eec4a4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20211010%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211010T230115Z&X-Amz-Expires=300&X-Amz-Signature=1acb19fd17e7cb4f74c5695b194dc2040b13d9649da64b191a53591758471718&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=4519663&response-content-disposition=attachment%3B%20filename%3DEasyRSA-3.0.7.tgz&response-content-type=application%2Foctet-stream
Resolving github-releases.githubusercontent.com (github-releases.githubusercontent.com)... 2606:50c0:8002::154, 2606:50c0:8003::154, 2606:50c0:8001::154, ...
Connecting to github-releases.githubusercontent.com (github-releases.githubusercontent.com)|2606:50c0:8002::154|:443... ^C

You could see, all of the IP addresses wget used are in IPV6 format while my network doesn't support IPV6 . So it is easy to fix. According to this question from stackoverflow, I added the following line at the end of /etc/wgetrc and the issue has gone!

inet4_only = on

What is good code? and what attributes do you think an ideal software developer demonstrates?

I was asked those questions recently and the following is my answer:

What is good code?

Good code has at least the following characteristics:

  • Good code has good readability, so it is easy to understand.

    • Good code is well organized, a clear and reasonable directory structure with meaningful filename is the basic element of good code.
    • Every class, method, variable has a deliberate and meaningful name. You can know the purpose of an identifier through the name at first glance.
    • Methods should be short, every method should only do one thing.
    • Good code does not use magic numbers and hard coded strings.
  • Good code has automated tests, so it is easy to maintain or change.

  • Good code has a good architecture, so its components can easily be replaced by another.

  • Good code has explicit dependencies.

  • Good code has good performance.

    • It does not do database queries or other time-consuming jobs in a loop.
  • It should use a queue for certain situations

  • It should use a full-text search engine instead of the 'LIKE' query on the database.

  • If part of the code is really complex, a carefully written comment would be helpful. By the way, do not forget to update the comment when you change the code later.

  • Good code is highly cohesive and low coupling. Components should be well defined, that is, they are self-contained with one and only one purpose. Each component should know as little as possible about another component.

  • Good code is modular. The Business logic (the controller) should be separated from the data storage layer (the model), while the view layer should be separated from the controller layer.

What attributes do you think an ideal software developer demonstrates?

  • They should always have enthusiasm for programming, which means that they programming not only at work.
  • They should know Linux or macOS well. I mean they should know the command line well.
  • They care about the user experience.
  • They are responsible and willing to do their best to meet the deadline.
  • They are knowledgeable, I mean they know not only programming, they have wide knowledge in various fields.
  • They love sharing and teaching, or mentoring. I mean they are kind to newbies.

What do you believe is the difference in behaviours and skills between a Senior Software Engineer and an Intermediate Software Engineer?

  • A senior engineer not only knows how to code or how to implement a feature but also knows how to code in a better way. They not only implement a feature, they help refine the feature. I mean they do extra work to make the feature better.
  • Senior engineers know how to plan, separate big tasks into smaller ones, and can recognize which task has the higher priority.
  • Senior engineers not only program, they help other engineers grow up. They do mentoring, tutoring, or teaching in a team.
  • Senior engineers are people beyond the bounds of skillset. They could be a potential leader, or just a leader without a title.

Approval Testing is tasty

Just record a few tips here:

[UseApprovalSubdirectory("Approvals")] can be used to set up the directory that saves the approval results.

It can be used for a test class or a test method.

Links

ApprovalTests.Net Project

An awesome entry to better code: The gilded rose kata

For some reason, I was told an interesting github repo, The Gilded Rose Kata. It really grasps my attention. The code's behavior is correct, but both code quality and code style are terrible. The author of the repo made it so bad on purpose. So it is the best material to teach newbies how to refactor.

From the Readme file of the repo, I learnt some new tools, one is the text based approval test. I actually know that concept before many years ago, but never practiced it. I just found it is easy to setup and easy to run. It tests your code from a new angle. I believe it could belong to a kind of greybox test. You need to know the code to test, but you don't know too much like other unit test methods.

I have done the refactoring, and my result has been put on Github.com

  1. first approach is on the main branch https://github.com/shukebeta/GildedRose-Refactoring-Kata/tree/main/csharpcore

  2. a better approach is on the other branch https://github.com/shukebeta/GildedRose-Refactoring-Kata/tree/simple-factory-pattern-approch

Here are some good links, and I would update it timely.

Writing good tests for the gilded rose kata
Principles for agile test automation
The gilded rose refactoring kata
How to refactor gildedrose refactoring kata with simple factory pattern and strategy pattern